AbstractFilterResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 28
ccs 8
cts 9
cp 0.8889
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 15 3
1
<?php declare(strict_types = 1);
2
3
namespace Apicart\FQL\Generator\SQL\Resolver;
4
5
use InvalidArgumentException;
6
7
abstract class AbstractFilterResolver
8
{
9
10
    /**
11
     * @param array<int, mixed> $values
12
     */
13 1
    public function resolve(string $column, ...$values): string
14
    {
15 1
        $mapping = $this->getResolvers();
16 1
        foreach ($mapping as $pattern => $resolver) {
17 1
            $matches = [];
18 1
            if ((bool) preg_match_all("#^{$pattern}$#", $column, $matches, PREG_SET_ORDER) === false) {
19 1
                continue;
20
            }
21
22 1
            array_push($values, $matches);
23
24 1
            return call_user_func_array($resolver, $values);
25
        }
26
27
        throw new InvalidArgumentException($column);
28
    }
29
30
31
    /**
32
     * @return callable[]
33
     */
34
    abstract protected function getResolvers(): array;
35
36
}
37