Total Complexity | 3 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | final class ActionChargingException extends RuntimeException |
||
16 | { |
||
17 | private readonly ActionInterface $action; |
||
18 | |||
19 | public static function forAction(ActionInterface $action, Throwable $previousException): self |
||
20 | { |
||
21 | if ($action->getId() !== null) { |
||
|
|||
22 | $message = sprintf('Failed to charge action %s: %s', $action->getId(), $previousException->getMessage()); |
||
23 | } else { |
||
24 | $message = sprintf( |
||
25 | 'Failed to charge action (type: %s, target: %s, quantity: %s %s, customer: %s, time: %s): %s', |
||
26 | $action->getType()->getName(), $action->getTarget()->getUniqueId(), |
||
27 | $action->getQuantity()->getQuantity(), $action->getQuantity()->getUnit()->getName(), |
||
28 | $action->getCustomer()->getLogin(), |
||
29 | $action->getTime()->format(DATE_ATOM), |
||
30 | $previousException->getMessage() |
||
31 | ); |
||
32 | } |
||
33 | |||
34 | $self = new self($message, 0, $previousException); |
||
35 | $self->action = $action; |
||
36 | |||
37 | return $self; |
||
38 | } |
||
39 | |||
40 | public function getAction(): ActionInterface |
||
43 | } |
||
44 | } |
||
45 |