| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | final readonly class CommandInterceptor implements MethodInterceptor |
||
|
|
|||
| 16 | { |
||
| 17 | /** @param CommandInterface[] $commands */ |
||
| 18 | public function __construct( |
||
| 19 | #[Commands] |
||
| 20 | private array $commands, |
||
| 21 | ) { |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritDoc} |
||
| 26 | 13 | * |
|
| 27 | * @throws ReturnValueIsNotResourceObjectException |
||
| 28 | 13 | */ |
|
| 29 | 13 | #[Override] |
|
| 30 | public function invoke(MethodInvocation $invocation) |
||
| 31 | { |
||
| 32 | /** @psalm-suppress MixedAssignment */ |
||
| 33 | $ro = $invocation->proceed(); |
||
| 34 | if (! $ro instanceof ResourceObject) { |
||
| 35 | throw new ReturnValueIsNotResourceObjectException($invocation->getThis()::class); |
||
| 36 | 10 | } |
|
| 37 | |||
| 38 | 10 | if ($ro->code >= Code::BAD_REQUEST) { |
|
| 39 | 10 | return $ro; |
|
| 40 | 1 | } |
|
| 41 | |||
| 42 | foreach ($this->commands as $command) { |
||
| 43 | 9 | $command->command($invocation, $ro); |
|
| 44 | 2 | } |
|
| 45 | |||
| 46 | return $ro; |
||
| 47 | 8 | } |
|
| 49 |