From 81f27645a6986172dea74a42dba1dbf2db554f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Tournayre?= Date: Mon, 24 Nov 2025 23:43:40 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(collection):=20typage=20?= =?UTF-8?q?explicite=20param=C3=A8tre=20$key=20dans=20UnshiftInterface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajoute type int|string|null pour $key (était untyped, causait ParseError PHPStan). --- src/Contracts/Collection/UnshiftInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contracts/Collection/UnshiftInterface.php b/src/Contracts/Collection/UnshiftInterface.php index 4285de9..b51af3a 100644 --- a/src/Contracts/Collection/UnshiftInterface.php +++ b/src/Contracts/Collection/UnshiftInterface.php @@ -21,5 +21,5 @@ interface UnshiftInterface * * @api */ - public function unshift(mixed $value, $key = null): self; + public function unshift(mixed $value, int|string|null $key = null): self; } From 0b1ea761a4da932af41a4e26bba0c62eb1a0c735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Tournayre?= Date: Mon, 24 Nov 2025 23:43:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20feat(exception):=20impl=C3=A9me?= =?UTF-8?q?nter=20LoggableInterface=20via=20trait=20optionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #102: toutes exceptions doivent implémenter LoggableInterface. Solution choisie (Option A - Interface Segregation): - Créer LoggableThrowableTrait combinant ThrowableTrait + toLog() - Exceptions opt-in LoggableInterface (pas héritage forcé) - Flexibilité pour exceptions non-loggables si besoin Changements: - Nouveau trait LoggableThrowableTrait avec méthode toLog() - 6 exceptions Common/Exception implémentent LoggableInterface - ThrowableInterface reste indépendant (pas extends LoggableInterface) Avantages: - Respecte principe Interface Segregation (SOLID) - Composition plutôt que couplage fort - Limite 5 méthodes ThrowableInterface préservée --- .../Exception/BadMethodCallException.php | 5 ++- .../Exception/InvalidArgumentException.php | 5 ++- .../Exception/LoggableThrowableTrait.php | 39 +++++++++++++++++++ src/Common/Exception/MutableException.php | 5 ++- src/Common/Exception/NullException.php | 5 ++- src/Common/Exception/RuntimeException.php | 5 ++- .../Exception/UnexpectedValueException.php | 5 ++- 7 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/Common/Exception/LoggableThrowableTrait.php diff --git a/src/Common/Exception/BadMethodCallException.php b/src/Common/Exception/BadMethodCallException.php index 7f19d96..727a101 100644 --- a/src/Common/Exception/BadMethodCallException.php +++ b/src/Common/Exception/BadMethodCallException.php @@ -5,8 +5,9 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class BadMethodCallException extends \BadMethodCallException implements ThrowableInterface +class BadMethodCallException extends \BadMethodCallException implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; } diff --git a/src/Common/Exception/InvalidArgumentException.php b/src/Common/Exception/InvalidArgumentException.php index ab76a77..8955494 100644 --- a/src/Common/Exception/InvalidArgumentException.php +++ b/src/Common/Exception/InvalidArgumentException.php @@ -5,8 +5,9 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class InvalidArgumentException extends \InvalidArgumentException implements ThrowableInterface +class InvalidArgumentException extends \InvalidArgumentException implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; } diff --git a/src/Common/Exception/LoggableThrowableTrait.php b/src/Common/Exception/LoggableThrowableTrait.php new file mode 100644 index 0000000..702700d --- /dev/null +++ b/src/Common/Exception/LoggableThrowableTrait.php @@ -0,0 +1,39 @@ + + */ + public function toLog(): array + { + return [ + 'message' => $this->getMessage(), + 'code' => $this->getCode(), + 'file' => $this->getFile(), + 'line' => $this->getLine(), + 'trace' => $this->getTraceAsString(), + ]; + } +} diff --git a/src/Common/Exception/MutableException.php b/src/Common/Exception/MutableException.php index 092995f..7255470 100644 --- a/src/Common/Exception/MutableException.php +++ b/src/Common/Exception/MutableException.php @@ -5,10 +5,11 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class MutableException extends \RuntimeException implements ThrowableInterface +class MutableException extends \RuntimeException implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; public static function becauseMustBeImmutable(): self { diff --git a/src/Common/Exception/NullException.php b/src/Common/Exception/NullException.php index 6a359b0..a358928 100644 --- a/src/Common/Exception/NullException.php +++ b/src/Common/Exception/NullException.php @@ -5,10 +5,11 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class NullException extends \Exception implements ThrowableInterface +class NullException extends \Exception implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; /** * @api diff --git a/src/Common/Exception/RuntimeException.php b/src/Common/Exception/RuntimeException.php index 61d263a..dddecf3 100644 --- a/src/Common/Exception/RuntimeException.php +++ b/src/Common/Exception/RuntimeException.php @@ -5,8 +5,9 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class RuntimeException extends \RuntimeException implements ThrowableInterface +class RuntimeException extends \RuntimeException implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; } diff --git a/src/Common/Exception/UnexpectedValueException.php b/src/Common/Exception/UnexpectedValueException.php index 43b1162..739ba85 100644 --- a/src/Common/Exception/UnexpectedValueException.php +++ b/src/Common/Exception/UnexpectedValueException.php @@ -5,8 +5,9 @@ namespace Atournayre\Common\Exception; use Atournayre\Contracts\Exception\ThrowableInterface; +use Atournayre\Contracts\Log\LoggableInterface; -class UnexpectedValueException extends \UnexpectedValueException implements ThrowableInterface +class UnexpectedValueException extends \UnexpectedValueException implements ThrowableInterface, LoggableInterface { - use ThrowableTrait; + use LoggableThrowableTrait; }