From c67f0a15a0a0b059489f8c7698093196beb8a381 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Sun, 23 Dec 2018 15:02:23 +0100 Subject: [PATCH 1/4] Rename marker interface to avoid confusion with code interface --- src/BadFunctionCallException.php | 2 +- src/BadMethodCallException.php | 2 +- src/DomainException.php | 2 +- src/{Throwable.php => InformativeException.php} | 2 +- src/InvalidArgumentException.php | 2 +- src/LengthException.php | 2 +- src/LogicException.php | 2 +- src/OutOfBoundsException.php | 2 +- src/OutOfRangeException.php | 2 +- src/OverflowException.php | 2 +- src/RangeException.php | 2 +- src/RuntimeException.php | 2 +- src/ThrowableContextTrait.php | 2 +- src/UnderflowException.php | 2 +- src/UnexpectedValueException.php | 2 +- tests/ReadExceptionContextTest.php | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) rename src/{Throwable.php => InformativeException.php} (80%) diff --git a/src/BadFunctionCallException.php b/src/BadFunctionCallException.php index d519e91..d440166 100644 --- a/src/BadFunctionCallException.php +++ b/src/BadFunctionCallException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class BadFunctionCallException extends \BadFunctionCallException implements Throwable +class BadFunctionCallException extends \BadFunctionCallException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/BadMethodCallException.php b/src/BadMethodCallException.php index 7e4c00a..ea1bc93 100644 --- a/src/BadMethodCallException.php +++ b/src/BadMethodCallException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class BadMethodCallException extends \BadMethodCallException implements Throwable +class BadMethodCallException extends \BadMethodCallException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/DomainException.php b/src/DomainException.php index d64870b..3d42328 100644 --- a/src/DomainException.php +++ b/src/DomainException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class DomainException extends \DomainException implements Throwable +class DomainException extends \DomainException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/Throwable.php b/src/InformativeException.php similarity index 80% rename from src/Throwable.php rename to src/InformativeException.php index 5f75c02..47c7c05 100644 --- a/src/Throwable.php +++ b/src/InformativeException.php @@ -8,7 +8,7 @@ /** * Marker interface for exceptions with context information. */ -interface Throwable extends \Throwable +interface InformativeException extends \Throwable { public function getContext() : array; } diff --git a/src/InvalidArgumentException.php b/src/InvalidArgumentException.php index 16d23be..7512dd5 100644 --- a/src/InvalidArgumentException.php +++ b/src/InvalidArgumentException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class InvalidArgumentException extends \InvalidArgumentException implements Throwable +class InvalidArgumentException extends \InvalidArgumentException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/LengthException.php b/src/LengthException.php index d657aa8..47dc88a 100644 --- a/src/LengthException.php +++ b/src/LengthException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class LengthException extends \LengthException implements Throwable +class LengthException extends \LengthException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/LogicException.php b/src/LogicException.php index 2f9aef9..a3fdb8b 100644 --- a/src/LogicException.php +++ b/src/LogicException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class LogicException extends \LogicException implements Throwable +class LogicException extends \LogicException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OutOfBoundsException.php b/src/OutOfBoundsException.php index 823aea5..1bb3758 100644 --- a/src/OutOfBoundsException.php +++ b/src/OutOfBoundsException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OutOfBoundsException extends \OutOfBoundsException implements Throwable +class OutOfBoundsException extends \OutOfBoundsException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OutOfRangeException.php b/src/OutOfRangeException.php index 980c2e3..32a0d62 100644 --- a/src/OutOfRangeException.php +++ b/src/OutOfRangeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OutOfRangeException extends \OutOfRangeException implements Throwable +class OutOfRangeException extends \OutOfRangeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OverflowException.php b/src/OverflowException.php index 2ba2af7..dc4814b 100644 --- a/src/OverflowException.php +++ b/src/OverflowException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OverflowException extends \OverflowException implements Throwable +class OverflowException extends \OverflowException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/RangeException.php b/src/RangeException.php index a60b3c7..7021340 100644 --- a/src/RangeException.php +++ b/src/RangeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class RangeException extends \RangeException implements Throwable +class RangeException extends \RangeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/RuntimeException.php b/src/RuntimeException.php index 65496c0..5958e79 100644 --- a/src/RuntimeException.php +++ b/src/RuntimeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class RuntimeException extends \RuntimeException implements Throwable +class RuntimeException extends \RuntimeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/ThrowableContextTrait.php b/src/ThrowableContextTrait.php index 09970b7..476ba23 100644 --- a/src/ThrowableContextTrait.php +++ b/src/ThrowableContextTrait.php @@ -9,7 +9,7 @@ trait ThrowableContextTrait { private $context = []; - public function __construct(string $message = '', array $context = [], int $code = 0, Throwable $previous = null) + public function __construct(string $message = '', array $context = [], int $code = 0, InformativeException $previous = null) { parent::__construct($message, $code, $previous); diff --git a/src/UnderflowException.php b/src/UnderflowException.php index 7fcb23f..8b45c9b 100644 --- a/src/UnderflowException.php +++ b/src/UnderflowException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class UnderflowException extends \UnderflowException implements Throwable +class UnderflowException extends \UnderflowException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/UnexpectedValueException.php b/src/UnexpectedValueException.php index aeb6f5d..46da70f 100644 --- a/src/UnexpectedValueException.php +++ b/src/UnexpectedValueException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class UnexpectedValueException extends \UnexpectedValueException implements Throwable +class UnexpectedValueException extends \UnexpectedValueException implements InformativeException { use ThrowableContextTrait; } diff --git a/tests/ReadExceptionContextTest.php b/tests/ReadExceptionContextTest.php index 4f80d12..336f85b 100644 --- a/tests/ReadExceptionContextTest.php +++ b/tests/ReadExceptionContextTest.php @@ -22,7 +22,7 @@ public function exceptionObjectShouldContainContext(string $exceptionClass): voi $exception = new $exceptionClass($message, $context, $code); - if ($exception instanceof Exceptions\Throwable) { + if ($exception instanceof Exceptions\InformativeException) { self::assertSame($message, $exception->getMessage()); self::assertSame($context, $exception->getContext()); self::assertSame($code, $exception->getCode()); From 04361391055992d99e722d8c92ff4250bd898379 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Sun, 23 Dec 2018 15:04:07 +0100 Subject: [PATCH 2/4] Fix base constructor, accept previous throwable --- src/InformativeException.php | 2 +- src/ThrowableContextTrait.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/InformativeException.php b/src/InformativeException.php index 47c7c05..7ae9d3c 100644 --- a/src/InformativeException.php +++ b/src/InformativeException.php @@ -10,5 +10,5 @@ */ interface InformativeException extends \Throwable { - public function getContext() : array; + public function getContext(): array; } diff --git a/src/ThrowableContextTrait.php b/src/ThrowableContextTrait.php index 476ba23..6efcbd1 100644 --- a/src/ThrowableContextTrait.php +++ b/src/ThrowableContextTrait.php @@ -9,14 +9,14 @@ trait ThrowableContextTrait { private $context = []; - public function __construct(string $message = '', array $context = [], int $code = 0, InformativeException $previous = null) + public function __construct(string $message = '', array $context = [], int $code = 0, \Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->context = $context; } - public function getContext() : array + public function getContext(): array { return $this->context; } From 0aea563b76af376a744b480c8d0a97dc77a5b3e5 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Sun, 23 Dec 2018 15:06:08 +0100 Subject: [PATCH 3/4] Cover usage exception with previous throwable injected into constructor --- tests/ReadExceptionContextTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ReadExceptionContextTest.php b/tests/ReadExceptionContextTest.php index 336f85b..2fbfafa 100644 --- a/tests/ReadExceptionContextTest.php +++ b/tests/ReadExceptionContextTest.php @@ -19,13 +19,15 @@ public function exceptionObjectShouldContainContext(string $exceptionClass): voi $message = 'Something went wrong'; $code = PHP_INT_MAX; $context = ['foo' => 'bar']; + $previous = new \Exception('Something went wrong'); - $exception = new $exceptionClass($message, $context, $code); + $exception = new $exceptionClass($message, $context, $code, $previous); if ($exception instanceof Exceptions\InformativeException) { self::assertSame($message, $exception->getMessage()); self::assertSame($context, $exception->getContext()); self::assertSame($code, $exception->getCode()); + self::assertSame($previous, $exception->getPrevious()); } else { self::fail('Invalid exception class'); } From 40b0e7de595b77cc091e333a71e91f663a866d5b Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Sun, 23 Dec 2018 15:08:39 +0100 Subject: [PATCH 4/4] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a544ff0..ca306b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,6 @@ Security - in case of vulnerabilities. _TBD_ -## [0.1.0] 2018-12-08 +## [1.0.0] 2018-12-23 Initial release.