| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 64.29% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | abstract class AbstractSorter implements CollectionSorterInterface |
||
| 10 | { |
||
| 11 | 18 | public function sort(array $array, string $order): array |
|
| 12 | { |
||
| 13 | 18 | $this->validateOrder($order); |
|
| 14 | |||
| 15 | 12 | $array = $array; |
|
| 16 | |||
| 17 | 12 | usort($array, $this->getSortingFunction($order)); |
|
| 18 | |||
| 19 | 12 | return $array; |
|
| 20 | } |
||
| 21 | |||
| 22 | public function ksort(array $array, string $order): array |
||
| 23 | { |
||
| 24 | $this->validateOrder($order); |
||
| 25 | |||
| 26 | $array = $array; |
||
| 27 | |||
| 28 | uksort($array, $this->getSortingFunction($order)); |
||
| 29 | |||
| 30 | return $array; |
||
| 31 | } |
||
| 32 | |||
| 33 | 12 | protected function resolveEntriesOrder($a, $b, string $order): int |
|
| 34 | { |
||
| 35 | 12 | return ($a <=> $b) * ($order === OrderInterface::DESC ? -1 : 1); |
|
| 36 | } |
||
| 37 | |||
| 38 | 18 | protected function validateOrder($order): void |
|
| 41 | } |
||
| 42 | |||
| 43 | abstract protected function getSortingFunction(string $order): callable; |
||
| 44 | } |
||
| 45 |