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