| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | /** |
||
| 16 | * Interceptor for cache invalidation on CQRS commands with #[Purge] or #[Refresh] |
||
| 17 | * |
||
| 18 | * Bound to command methods (onPut/onPatch/onDelete) of #[Cacheable] classes. |
||
| 19 | * Executes cache invalidation after successful write operations. |
||
| 20 | * |
||
| 21 | * @see \BEAR\RepositoryModule\Annotation\Purge |
||
| 22 | * @see \BEAR\RepositoryModule\Annotation\Refresh |
||
| 23 | * @see https://bearsunday.github.io/manuals/1.0/en/cache.html#tag-based-cache-invalidation |
||
| 24 | */ |
||
| 25 | final readonly class CommandInterceptor implements MethodInterceptor |
||
|
|
|||
| 26 | 13 | { |
|
| 27 | /** @param CommandInterface[] $commands */ |
||
| 28 | 13 | public function __construct( |
|
| 29 | 13 | #[Commands] |
|
| 30 | private array $commands, |
||
| 31 | ) { |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritDoc} |
||
| 36 | 10 | * |
|
| 37 | * @throws ReturnValueIsNotResourceObjectException |
||
| 38 | 10 | */ |
|
| 39 | 10 | #[Override] |
|
| 40 | 1 | public function invoke(MethodInvocation $invocation) |
|
| 41 | { |
||
| 42 | /** @psalm-suppress MixedAssignment */ |
||
| 43 | 9 | $ro = $invocation->proceed(); |
|
| 44 | 2 | if (! $ro instanceof ResourceObject) { |
|
| 45 | throw new ReturnValueIsNotResourceObjectException($invocation->getThis()::class); |
||
| 46 | } |
||
| 47 | 8 | ||
| 59 |