RefreshInterceptor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 14 3
A __construct() 0 3 1
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