RefreshInterceptor::invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 14
rs 10
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 class RefreshInterceptor implements MethodInterceptor
15
{
16
    public function __construct(
17
        private readonly 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