Constraint::isAllowedOrder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
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