| Total Complexity | 11 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | final class Sort implements ExtensibleSorting |
||
| 19 | { |
||
| 20 | private $field; |
||
| 21 | private $ascends; |
||
| 22 | private $next; |
||
| 23 | |||
| 24 | private function __construct( |
||
| 25 | string $field, |
||
| 26 | bool $ascends, |
||
| 27 | Sorting $next |
||
| 28 | ) { |
||
| 29 | $this->field = $field; |
||
| 30 | $this->ascends = $ascends; |
||
| 31 | $this->next = $next; |
||
| 32 | } |
||
| 33 | |||
| 34 | public static function descendingBy( |
||
| 35 | string $field, |
||
| 36 | Sorting $next = null |
||
| 37 | ): ExtensibleSorting { |
||
| 38 | return new Sort($field, false, $next ?: DoNotSort::atAll()); |
||
| 39 | } |
||
| 40 | |||
| 41 | public static function ascendingBy( |
||
| 42 | string $field, |
||
| 43 | Sorting $next = null |
||
| 44 | ): ExtensibleSorting { |
||
| 45 | return new Sort($field, true, $next ?: DoNotSort::atAll()); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function field(): string |
||
| 49 | { |
||
| 50 | return $this->field; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function next(): Sorting |
||
| 54 | { |
||
| 55 | return $this->next; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function ascends(): bool |
||
| 59 | { |
||
| 60 | return $this->ascends; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function isRequired(): bool |
||
| 64 | { |
||
| 65 | return true; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function andThenAscendingBy(string $field): ExtensibleSorting |
||
| 69 | { |
||
| 70 | return new Sort($this->field, $this->ascends, Sort::ascendingBy($field)); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function andThenDescendingBy(string $field): ExtensibleSorting |
||
| 76 | } |
||
| 77 | } |
||
| 78 |