Total Complexity | 10 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Coverage | 84% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Sort |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $property; |
||
16 | |||
17 | /** |
||
18 | * @var \Zing\QueryBuilder\Contracts\Sort |
||
19 | */ |
||
20 | protected $sort; |
||
21 | |||
22 | protected $column; |
||
23 | |||
24 | protected $defaultDirection; |
||
25 | |||
26 | /** |
||
27 | * Sort constructor. |
||
28 | * |
||
29 | * @param string $property |
||
30 | * @param string $column |
||
31 | */ |
||
32 | 3 | public function __construct(string $property, Contracts\Sort $sort, $column) |
|
33 | { |
||
34 | 3 | $this->property = $property; |
|
35 | 3 | $this->sort = $sort; |
|
36 | 3 | $this->column = $column ?? $property; |
|
37 | 3 | } |
|
38 | |||
39 | 3 | public static function field(string $property, $column = null): self |
|
40 | { |
||
41 | 3 | return new static($property, new SortField(), $column); |
|
42 | } |
||
43 | |||
44 | 3 | public function getProperty(): string |
|
45 | { |
||
46 | 3 | return $this->property; |
|
47 | } |
||
48 | |||
49 | public function isForProperty(string $property): bool |
||
50 | { |
||
51 | return $this->property === $property; |
||
52 | } |
||
53 | |||
54 | public function getColumn(): string |
||
55 | { |
||
56 | return $this->column; |
||
57 | } |
||
58 | |||
59 | 1 | public function asc() |
|
60 | { |
||
61 | 1 | $this->defaultDirection = 'asc'; |
|
62 | |||
63 | 1 | return $this; |
|
64 | } |
||
65 | |||
66 | 1 | public function desc() |
|
67 | { |
||
68 | 1 | $this->defaultDirection = 'desc'; |
|
69 | |||
70 | 1 | return $this; |
|
71 | } |
||
72 | |||
73 | 1 | public function hasDefaultDirection(): bool |
|
74 | { |
||
75 | 1 | return $this->defaultDirection !== null; |
|
76 | } |
||
77 | |||
78 | 1 | public function getDefaultDirection() |
|
79 | { |
||
80 | 1 | return $this->defaultDirection; |
|
81 | } |
||
82 | |||
83 | 3 | public function sort($query, $direction): Builder |
|
86 | } |
||
87 | } |
||
88 |