From 8b39422123c9a4a9f9c7da6df38004613fdcde96 Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Thu, 29 Dec 2022 23:34:23 +1000 Subject: [PATCH] Turn abstract exception into an interface --- src/Exceptions/JsonParserException.php | 8 ++------ src/Exceptions/PointerException.php | 8 ++++++-- src/Exceptions/SourceException.php | 11 ++++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Exceptions/JsonParserException.php b/src/Exceptions/JsonParserException.php index 20e67cc..f7f05f8 100644 --- a/src/Exceptions/JsonParserException.php +++ b/src/Exceptions/JsonParserException.php @@ -2,16 +2,12 @@ namespace Cerbero\JsonParser\Exceptions; -use Exception; +use Throwable; /** * Any exception thrown by JSON Parser. * */ -abstract class JsonParserException extends Exception +interface JsonParserException extends Throwable { - public const SOURCE_UNSUPPORTED = 0; - public const SOURCE_GUZZLE = 1; - - public const POINTER_INVALID = 0; } diff --git a/src/Exceptions/PointerException.php b/src/Exceptions/PointerException.php index 5d95831..d4ba869 100644 --- a/src/Exceptions/PointerException.php +++ b/src/Exceptions/PointerException.php @@ -2,12 +2,16 @@ namespace Cerbero\JsonParser\Exceptions; +use Exception; + /** * The exception thrown when a pointer-related error occurs. * */ -final class PointerException extends JsonParserException +final class PointerException extends Exception implements JsonParserException { + public const CODE_INVALID = 0; + /** * Retrieve the exception when the given pointer is invalid * @@ -16,6 +20,6 @@ final class PointerException extends JsonParserException */ public static function invalid(string $pointer): static { - return new static("The string [$pointer] is not a valid JSON pointer", static::POINTER_INVALID); + return new static("The string [$pointer] is not a valid JSON pointer", static::CODE_INVALID); } } diff --git a/src/Exceptions/SourceException.php b/src/Exceptions/SourceException.php index 5f51b68..4e50da1 100644 --- a/src/Exceptions/SourceException.php +++ b/src/Exceptions/SourceException.php @@ -2,12 +2,17 @@ namespace Cerbero\JsonParser\Exceptions; +use Exception; + /** * The exception thrown when a source-related error occurs. * */ -final class SourceException extends JsonParserException +final class SourceException extends Exception implements JsonParserException { + public const CODE_UNSUPPORTED = 0; + public const CODE_GUZZLE = 1; + /** * Retrieve the exception when a JSON source is not supported * @@ -15,7 +20,7 @@ final class SourceException extends JsonParserException */ public static function unsupported(): static { - return new static('Unable to load JSON from the provided source', static::SOURCE_UNSUPPORTED); + return new static('Unable to load JSON from the provided source', static::CODE_UNSUPPORTED); } /** @@ -25,6 +30,6 @@ final class SourceException extends JsonParserException */ public static function requireGuzzle(): static { - return new static('Guzzle is required to load JSON from endpoints', static::SOURCE_GUZZLE); + return new static('Guzzle is required to load JSON from endpoints', static::CODE_GUZZLE); } }