diff --git a/app/Core/Validators/PNValidator.php b/app/Core/Validators/PNValidator.php index a7d00194..57613bb3 100644 --- a/app/Core/Validators/PNValidator.php +++ b/app/Core/Validators/PNValidator.php @@ -5,7 +5,7 @@ namespace App\Core\Validators; use App\Exceptions\AppException\PNException\InvalidPNFormatException; -use App\Exceptions\AppException\PNException\NumericPNException; +use App\Exceptions\AppException\PNException\NotNumericPNException; use App\Exceptions\AppException\PNException\UnsupportedCodePNException; use function config; @@ -17,7 +17,7 @@ class PNValidator { /** - * @throws NumericPNException + * @throws NotNumericPNException * @throws InvalidPNFormatException * @throws UnsupportedCodePNException */ @@ -31,12 +31,12 @@ public function validate(string $pn): void } /** - * @throws NumericPNException + * @throws NotNumericPNException */ private function validateNumeric(string $pn): void { if (!is_numeric($pn)) { - throw new NumericPNException(); + throw new NotNumericPNException(); } } diff --git a/app/Exceptions/AppException.php b/app/Exceptions/AppException.php index d901b3c1..4d4b50c0 100644 --- a/app/Exceptions/AppException.php +++ b/app/Exceptions/AppException.php @@ -8,4 +8,17 @@ class AppException extends Exception { + protected const INVALID_FORMAT_PN = 100; + protected const NOT_NUMERIC_PN = 101; + protected const UNSUPPORTED_CODE_PN = 102; + + protected const INTERNAL_ERROR = 500; + + protected function __construct(string $message, int $code) + { + parent::__construct( + message: $message, + code: $code, + ); + } } diff --git a/app/Exceptions/AppException/PNException.php b/app/Exceptions/AppException/PNException.php index 03697a53..19e8ffe3 100644 --- a/app/Exceptions/AppException/PNException.php +++ b/app/Exceptions/AppException/PNException.php @@ -8,4 +8,11 @@ class PNException extends AppException { + protected function __construct(string $message, int $code) + { + parent::__construct( + message: $message, + code: $code, + ); + } } diff --git a/app/Exceptions/AppException/PNException/InvalidPNFormatException.php b/app/Exceptions/AppException/PNException/InvalidPNFormatException.php index daaf517a..0054aa0c 100644 --- a/app/Exceptions/AppException/PNException/InvalidPNFormatException.php +++ b/app/Exceptions/AppException/PNException/InvalidPNFormatException.php @@ -5,12 +5,14 @@ namespace App\Exceptions\AppException\PNException; use App\Exceptions\AppException\PNException; -use Throwable; -class InvalidPNFormatException extends PNException +final class InvalidPNFormatException extends PNException { - public function __construct(int $code = 0, ?Throwable $previous = null) + public function __construct() { - parent::__construct('Invalid phone number format', $code, $previous); + parent::__construct( + message: 'Invalid phone number format', + code: self::INVALID_FORMAT_PN, + ); } } diff --git a/app/Exceptions/AppException/PNException/NotNumericPNException.php b/app/Exceptions/AppException/PNException/NotNumericPNException.php new file mode 100644 index 00000000..59945186 --- /dev/null +++ b/app/Exceptions/AppException/PNException/NotNumericPNException.php @@ -0,0 +1,18 @@ +