RefreshInterceptor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 20
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 13 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 Ray\Aop\MethodInterceptor;
11
use Ray\Aop\MethodInvocation;
12
13
final class RefreshInterceptor implements MethodInterceptor
14
{
15
    public function __construct(
16
        private readonly RefreshAnnotatedCommand $command,
17
    ) {
18
    }
19
20 2
    public function invoke(MethodInvocation $invocation): ResourceObject
21
    {
22 2
        /** @psalm-suppress MixedAssignment */
23 2
        $ro = $invocation->proceed();
24
        if (! $ro instanceof ResourceObject) {
25 2
            throw new ReturnValueIsNotResourceObjectException($invocation->getThis()::class); // @codeCoverageIgnore
26
        }
27 2
28 2
        if ($ro->code < Code::BAD_REQUEST) {
29
            $this->command->command($invocation, $ro);
30
        }
31
32 2
        return $ro;
33 2
    }
34
}
35