RefreshInterceptor::invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
ccs 7
cts 8
cp 0.875
crap 3.0175
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