diff --git a/psalm.xml b/psalm.xml index c0bb9e83..9ac1a824 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,6 +14,7 @@ ensureArrayStringOffsetsExist="true" ensureArrayIntOffsetsExist="true" ignoreInternalFunctionFalseReturn="false" + ensureOverrideAttribute="false" > diff --git a/src/Exception/ActionChargingException.php b/src/Exception/ActionChargingException.php index 431b2484..6eafbed4 100644 --- a/src/Exception/ActionChargingException.php +++ b/src/Exception/ActionChargingException.php @@ -3,6 +3,8 @@ namespace hiqdev\php\billing\Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\action\ActionInterface; use Throwable; @@ -12,9 +14,9 @@ * * @author Dmytro Naumenko */ -final class ActionChargingException extends RuntimeException +final class ActionChargingException extends RuntimeException implements HasContextInterface { - private readonly ActionInterface $action; + use HasContext; public static function forAction(ActionInterface $action, Throwable $previousException): self { @@ -32,13 +34,8 @@ public static function forAction(ActionInterface $action, Throwable $previousExc } $self = new self($message, 0, $previousException); - $self->action = $action; + $self->addContext(['action' => $action]); return $self; } - - public function getAction(): ActionInterface - { - return $this->action; - } } diff --git a/src/Exception/CannotReassignException.php b/src/Exception/CannotReassignException.php index 284308e3..2c4491ae 100644 --- a/src/Exception/CannotReassignException.php +++ b/src/Exception/CannotReassignException.php @@ -11,24 +11,22 @@ namespace hiqdev\php\billing\Exception; use Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\ExceptionInterface; use Throwable; /** * @author Andrii Vasyliev */ -class CannotReassignException extends Exception implements ExceptionInterface +class CannotReassignException extends Exception implements ExceptionInterface, HasContextInterface { - private $field; + use HasContext; - public function __construct(string $message, int $code = 0, Throwable $previous = null) + public function __construct(string $message, int $code = 0, ?Throwable $previous = null) { - $this->field = $message; - parent::__construct("cannot reassign $message", $code, $previous); - } + $this->addContext(['field' => $message]); - public function getField() - { - return $this->field; + parent::__construct("cannot reassign $message", $code, $previous); } } diff --git a/src/Exception/ChargeOverlappingException.php b/src/Exception/ChargeOverlappingException.php index 3f304025..1430225d 100644 --- a/src/Exception/ChargeOverlappingException.php +++ b/src/Exception/ChargeOverlappingException.php @@ -10,13 +10,15 @@ namespace hiqdev\php\billing\Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\charge\ChargeInterface; use hiqdev\php\billing\ExceptionInterface; use Exception; -final class ChargeOverlappingException extends Exception implements ExceptionInterface +final class ChargeOverlappingException extends Exception implements ExceptionInterface, HasContextInterface { - private ChargeInterface $charge; + use HasContext; public static function forCharge(ChargeInterface $charge): self { @@ -25,13 +27,11 @@ public static function forCharge(ChargeInterface $charge): self $charge->getId(), $charge->getUniqueString() )); - $self->charge = $charge; + $self->addContext([ + 'chargeTypeName' => $charge->getType()->getName(), + 'chargeActionTime' => $charge->getAction()->getTime()->format(DATE_ATOM), + ]); return $self; } - - public function getCharge(): ChargeInterface - { - return $this->charge; - } } diff --git a/src/Exception/ChargeStealingException.php b/src/Exception/ChargeStealingException.php index 53bf0726..81ea286d 100644 --- a/src/Exception/ChargeStealingException.php +++ b/src/Exception/ChargeStealingException.php @@ -11,6 +11,8 @@ namespace hiqdev\php\billing\Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\charge\ChargeInterface; use hiqdev\php\billing\ExceptionInterface; use Exception; @@ -21,9 +23,9 @@ * * @author Dmytro Naumenko */ -final class ChargeStealingException extends Exception implements ExceptionInterface +final class ChargeStealingException extends Exception implements ExceptionInterface, HasContextInterface { - private ChargeInterface $charge; + use HasContext; public static function fromPdoException(ChargeInterface $charge, Exception $exception): self { @@ -31,7 +33,7 @@ public static function fromPdoException(ChargeInterface $charge, Exception $exce 'Charge being saved tries to steal an existing charge from another bill: %s', self::trimExceptionMessage($exception->getMessage()) )); - $self->charge = $charge; + $self->addContext(['charge' => $charge]); return $self; } @@ -40,9 +42,4 @@ private static function trimExceptionMessage(string $message): string { return preg_replace('/^.+ERROR:\s+([^\n]+).+$/s', '$1', $message); } - - public function getCharge(): ChargeInterface - { - return $this->charge; - } } diff --git a/src/formula/FormulaEngine.php b/src/formula/FormulaEngine.php index 9c88da0a..a1718b21 100755 --- a/src/formula/FormulaEngine.php +++ b/src/formula/FormulaEngine.php @@ -232,7 +232,7 @@ private function getOnce(): ChargeModifier return $this->once; } - public function __clone(): void + public function __clone() { if ($this->context !== null) { $this->context = clone $this->context; diff --git a/src/product/Domain/Model/Price/PriceTypeCollection.php b/src/product/Domain/Model/Price/PriceTypeCollection.php index 8b262199..9d374958 100644 --- a/src/product/Domain/Model/Price/PriceTypeCollection.php +++ b/src/product/Domain/Model/Price/PriceTypeCollection.php @@ -9,6 +9,9 @@ use IteratorAggregate; use Traversable; +/** + * @template-implements IteratorAggregate + */ class PriceTypeCollection implements IteratorAggregate, Countable { /**