Issues (61)

src/RefreshInterceptor.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\QueryRepository\Exception\ReturnValueIsNotResourceObjectException;
8
use BEAR\Resource\Code;
9
use BEAR\Resource\ResourceObject;
10
use Override;
11
use Ray\Aop\MethodInterceptor;
12
use Ray\Aop\MethodInvocation;
13
14
final readonly class RefreshInterceptor implements MethodInterceptor
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 14 at column 6
Loading history...
15
{
16
    public function __construct(
17
        private RefreshAnnotatedCommand $command,
18
    ) {
19
    }
20
21
    #[Override]
22
    public function invoke(MethodInvocation $invocation): ResourceObject
23
    {
24
        /** @psalm-suppress MixedAssignment */
25
        $ro = $invocation->proceed();
26
        if (! $ro instanceof ResourceObject) {
27
            throw new ReturnValueIsNotResourceObjectException($invocation->getThis()::class); // @codeCoverageIgnore
28
        }
29
30
        if ($ro->code < Code::BAD_REQUEST) {
31
            $this->command->command($invocation, $ro);
32
        }
33
34
        return $ro;
35
    }
36
}
37