Configuration   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setOrder() 0 12 2
B setFilter() 0 26 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Atlance\HttpDoctrineOrmFilter\Query;
6
7
use Atlance\HttpDoctrineOrmFilter\Utils\JsonNormalizer;
8
use Webmozart\Assert\Assert;
9
10
class Configuration extends AbstractCommand
11
{
12
    public int $page;
13
14
    public int $limit;
15
16
    public array $filter = [];
17
18
    public array $order = [];
19
20
    /** @psalm-suppress MixedArrayAssignment */
21 76
    public function setFilter(array $conditions): self
22
    {
23
        /**
24
         * @var string $exp
25
         * @var array  $values
26
         */
27 76
        foreach ($conditions as $exp => $values) {
28 76
            Assert::oneOf($exp, Builder::SUPPORTED_EXPRESSIONS);
29
            /**
30
             * @var string $propertyAlias
31
             * @var mixed  $value
32
             */
33 75
            foreach ($values as $propertyAlias => $value) {
34 75
                if (!\array_key_exists($exp, $this->filter)) {
35 75
                    $this->filter[$exp] = [];
36
                }
37
38 75
                if (\is_string($value) && preg_match('#\|#', $value)) {
39 30
                    $value = JsonNormalizer::normalize(explode('|', $value));
40
                }
41
42 75
                $this->filter[$exp][$propertyAlias] = \is_array($value) ? $value : [$value];
43
            }
44
        }
45
46 75
        return $this;
47
    }
48
49 2
    public function setOrder(array $conditions): self
50
    {
51
        /**
52
         * @var string $alias
53
         * @var string $direction
54
         */
55 2
        foreach ($conditions as $alias => $direction) {
56 2
            Assert::oneOf($direction, ['asc', 'desc']);
57 1
            $this->order[$alias] = $direction;
58
        }
59
60 1
        return $this;
61
    }
62
}
63