Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Order | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Finder; |
| 6 | |
| 7 | use Cosray\Exception\ParserException; |
| 8 | |
| 9 | /** A structured order term always places absent values last, in either direction. */ |
| 10 | final readonly class Order |
| 11 | { |
| 12 | public SortField $field; |
| 13 | public string $direction; |
| 14 | |
| 15 | public function __construct(string|SortField $field, string $direction = 'asc') |
| 16 | { |
| 17 | $this->field = is_string($field) ? SortField::text($field) : $field; |
| 18 | $this->direction = strtolower(trim($direction)); |
| 19 | |
| 20 | if (!in_array($this->direction, ['asc', 'desc'], true)) { |
| 21 | throw new ParserException("Invalid sort direction '{$direction}'"); |
| 22 | } |
| 23 | } |
| 24 | } |