Constraint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 7
c 1
b 0
f 0
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setFilters() 0 3 1
A isAllowedOrder() 0 3 2
A setOrders() 0 3 1
A isAllowedFilter() 0 3 2
1
<?php declare(strict_types=1);
2
3
namespace Mgid\Component\Pagination\Mapping;
4
5
final class Constraint implements ConstraintInterface
6
{
7
    /**
8
     * @var string[]
9
     */
10
    private array $orders = [];
11
12
    /**
13
     * @var string[]
14
     */
15
    private array $filters = [];
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function setOrders(array $orders): void
21
    {
22
        $this->orders = $orders;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function isAllowedOrder(string $fieldName): bool
29
    {
30
        return empty($this->orders) || \in_array($fieldName, $this->orders, true);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function setFilters(array $filters): void
37
    {
38
        $this->filters = $filters;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function isAllowedFilter(string $fieldName): bool
45
    {
46
        return empty($this->filters) || \in_array($fieldName, $this->filters, true);
47
    }
48
}
49