Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 <d.naumenko.a@gmail.com>
*/
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;
}
}
14 changes: 6 additions & 8 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 <sol@hiqdev.com>
*/
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)
{
$this->field = $message;
parent::__construct("cannot reassign $message", $code, $previous);
}
$this->addContext(['filed' => $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: 6 additions & 7 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,19 @@
*
* @author Dmytro Naumenko <d.naumenko.a@gmail.com>
*/
final class ChargeStealingException extends Exception implements ExceptionInterface
final class ChargeStealingException extends Exception implements ExceptionInterface, HasContextInterface
{
use HasContext;

private ChargeInterface $charge;

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

View workflow job for this annotation

GitHub Actions / PHP 8.3

UnusedProperty

src/Exception/ChargeStealingException.php:30:29: UnusedProperty: Cannot find any references to private property hiqdev\php\billing\Exception\ChargeStealingException::$charge (see https://psalm.dev/150)

public static function fromPdoException(ChargeInterface $charge, Exception $exception): self

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

View workflow job for this annotation

GitHub Actions / PHP 8.3

PossiblyUnusedMethod

src/Exception/ChargeStealingException.php:32: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 +44,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, string>
*/
class PriceTypeCollection implements IteratorAggregate, Countable
{
/**
Expand Down
Loading