Skip to content

Commit

Permalink
Merge pull request #7 from KaririCode-Framework/develop
Browse files Browse the repository at this point in the history
refactor(SanitizationException): Replace instance-based exception wit…
  • Loading branch information
walmir-silva authored Oct 26, 2024
2 parents 19ff75c + 6ec0fab commit 9602c6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/Exception/SanitizationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

namespace KaririCode\Sanitizer\Exception;

final class SanitizationException extends \RuntimeException
use KaririCode\Exception\AbstractException;

final class SanitizationException extends AbstractException
{
private const CODE_INVALID_INPUT = 4001;

public static function invalidInput(string $expectedType): self
{
$message = sprintf(
'Input must be a %s',
$expectedType
);

return self::createException(
self::CODE_INVALID_INPUT,
'INVALID_INPUT',
$message
);
}
}
2 changes: 1 addition & 1 deletion src/Processor/AbstractSanitizerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class AbstractSanitizerProcessor implements Processor
protected function guardAgainstNonString(mixed $input): string
{
if (!is_string($input)) {
throw new SanitizationException('Input must be a string');
throw SanitizationException::invalidInput('string');
}

return $input;
Expand Down

0 comments on commit 9602c6d

Please sign in to comment.