MatchQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\QueryRepository\Exception\UnmatchedQuery;
8
use BEAR\Resource\ResourceObject;
9
use ReflectionMethod;
10
11
use function sprintf;
12
13
final class MatchQuery implements MatchQueryInterface
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    public function __invoke(ResourceObject $ro): array
19
    {
20
        $refParameters = (new ReflectionMethod($ro::class, 'onGet'))->getParameters();
21
        $getQuery = [];
22
        $query = $ro->uri->query;
23
        foreach ($refParameters as $parameter) {
24
            if (! isset($query[$parameter->name])) {
25
                throw new UnmatchedQuery(sprintf('%s %s', $ro->uri->method, (string) $ro->uri));
26
            }
27
28
            /** @psalm-suppress MixedAssignment */
29
            $getQuery[$parameter->name] = $query[$parameter->name];
30
        }
31
32
        return $getQuery;
33
    }
34
}
35