Completed
Push — 1.x ( cabfbb...654b76 )
by Akihito
65:48 queued 62:44
created

RefreshInterceptor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 26
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invoke() 0 13 3
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
    /**
16
     * @var RefreshAnnotatedCommand
17
     */
18
    private $command;
19
20 2
    public function __construct(RefreshAnnotatedCommand $command)
21
    {
22 2
        $this->command = $command;
23 2
    }
24
25 2
    public function invoke(MethodInvocation $invocation)
26
    {
27 2
        $ro = $invocation->proceed();
28 2
        if (! $ro instanceof ResourceObject) {
29
            throw new ReturnValueIsNotResourceObjectException(\get_class($invocation->getThis()));
30
        }
31
32 2
        if ($ro->code < Code::BAD_REQUEST) {
33 2
            $this->command->command($invocation, $ro);
34
        }
35
36 2
        return $ro;
37
    }
38
}
39