RefreshSameCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 10
c 5
b 1
f 0
dl 0
loc 37
ccs 18
cts 19
cp 0.9474
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getQuery() 0 3 1
A command() 0 15 2
1
<?php
2
3
namespace BEAR\QueryRepository;
4
5
use BEAR\Resource\ResourceObject;
6
use Ray\Aop\MethodInvocation;
7
use ReflectionException;
8
use function array_values;
9
use function call_user_func_array;
10
use function is_callable;
11
12
// phpcs:ignoreFile SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing -- for call_user_func_array
13
14
final class RefreshSameCommand implements CommandInterface
15
{
16
    public function __construct(
17
        private readonly QueryRepositoryInterface $repository,
18 13
        private readonly MatchQueryInterface $matchQuery
19
    ){
20 13
    }
21 13
22
    /**
23 8
     * @return void
24
     */
25 8
    public function command(MethodInvocation $invocation, ResourceObject $ro)
26 8
    {
27
        unset($invocation);
28
        $getQuery = $this->getQuery($ro);
29 8
        $delUri = clone $ro->uri;
30 8
        $delUri->query = $getQuery;
31 7
32 7
        // delete data in repository
33
        $this->repository->purge($delUri);
34
35 7
        // GET for re-generate (in interceptor)
36
        $ro->uri->query = $getQuery;
37
        $get = [$ro, 'onGet'];
38 7
        if (is_callable($get)) {
39 7
            call_user_func_array($get, array_values($getQuery));
40 7
        }
41
    }
42 7
43
    /**
44
     * @return array<string, mixed>
45
     *
46
     * @throws ReflectionException
47 8
     */
48
    private function getQuery(ResourceObject $ro): array
49 8
    {
50 8
        return $this->matchQuery->__invoke($ro);
51 8
    }
52
}
53