Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ensureArrayStringOffsetsExist="true"
ensureArrayIntOffsetsExist="true"
ignoreInternalFunctionFalseReturn="false"
ensureOverrideAttribute="false"
>
<projectFiles>
<directory name="src" />
Expand Down
13 changes: 5 additions & 8 deletions src/Exception/ActionChargingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -12,9 +14,9 @@
*
* @author Dmytro Naumenko <[email protected]>
*/
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
{
Expand All @@ -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;
}
}
16 changes: 7 additions & 9 deletions src/Exception/CannotReassignException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
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);
}
}
16 changes: 8 additions & 8 deletions src/Exception/ChargeOverlappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

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

Check failure on line 23 in src/Exception/ChargeOverlappingException.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

PossiblyUnusedMethod

src/Exception/ChargeOverlappingException.php:23:28: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\Exception\ChargeOverlappingException::forCharge (see https://psalm.dev/087)
{
$self = new self(sprintf(
'Charge %s being saved overlaps a previously saved one. Unique key: %s',
$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;
}
}
13 changes: 5 additions & 8 deletions src/Exception/ChargeStealingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,17 +23,17 @@
*
* @author Dmytro Naumenko <[email protected]>
*/
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

Check failure on line 30 in src/Exception/ChargeStealingException.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

PossiblyUnusedMethod

src/Exception/ChargeStealingException.php:30:28: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\Exception\ChargeStealingException::fromPdoException (see https://psalm.dev/087)
{
$self = new self(sprintf(
'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;
}
Expand All @@ -40,9 +42,4 @@
{
return preg_replace('/^.+ERROR:\s+([^\n]+).+$/s', '$1', $message);
}

public function getCharge(): ChargeInterface
{
return $this->charge;
}
}
2 changes: 1 addition & 1 deletion src/formula/FormulaEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/product/Domain/Model/Price/PriceTypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use IteratorAggregate;
use Traversable;

/**
* @template-implements IteratorAggregate<int, PriceTypeInterface>
*/
class PriceTypeCollection implements IteratorAggregate, Countable
{
/**
Expand Down
Loading