Total Complexity | 6 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Coverage | 56.25% |
Changes | 0 |
1 | <?php |
||
10 | class OrderBy implements CriteriaInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $column; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $direction; |
||
21 | |||
22 | /** |
||
23 | * Allowed characters for order by column |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $allowedToContain = '/^[a-z0-9\.\_\-]+$/i'; |
||
28 | |||
29 | /** |
||
30 | * OrderBy constructor. |
||
31 | * |
||
32 | * @param mixed $orderBy |
||
33 | */ |
||
34 | 2 | public function __construct($orderBy) |
|
37 | 2 | } |
|
38 | |||
39 | /** |
||
40 | * @param $orderBy |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | 1 | public function setOrderByParameters($orderBy): void |
|
45 | { |
||
46 | 1 | [$column, $direction] = explode(',', $orderBy); |
|
47 | |||
48 | 1 | $this->column = $column; |
|
49 | 1 | $this->direction = $direction ?? 'asc'; |
|
50 | |||
51 | 1 | if (! \in_array($this->direction, ['asc', 'desc'])) { |
|
52 | $this->direction = 'asc'; |
||
53 | } |
||
54 | 1 | } |
|
55 | |||
56 | /** |
||
57 | * @param $model |
||
58 | * @param RepositoryInterface $repository |
||
59 | * |
||
60 | * @throws ValidationException |
||
61 | * |
||
62 | * @return Builder |
||
63 | */ |
||
64 | public function apply($model, RepositoryInterface $repository): Builder |
||
77 | } |
||
78 | } |
||
79 |