seboettg /
Collection
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | /* |
||
| 4 | * Copyright (C) 2016 Sebastian Böttger <[email protected]> |
||
| 5 | * You may use, distribute and modify this code under the |
||
| 6 | * terms of the MIT license. |
||
| 7 | * |
||
| 8 | * You should have received a copy of the MIT license with |
||
| 9 | * this file. If not, please visit: https://opensource.org/licenses/mit-license.php |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Seboettg\Collection\Comparable; |
||
| 13 | |||
| 14 | abstract class Comparator |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * static constant for sorting order ascending |
||
| 19 | */ |
||
| 20 | public const ORDER_ASC = "ASC"; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * static constant for sorting order descending |
||
| 24 | */ |
||
| 25 | public const ORDER_DESC = "DESC"; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * static constant for a custom sorting order |
||
| 29 | */ |
||
| 30 | public const ORDER_CUSTOM = "CUSTOM"; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * defines the order (ascending|descending) for a comparison |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $sortingOrder; |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 38 | |||
| 39 | /** |
||
| 40 | * object/array which can be used to define a custom order |
||
| 41 | * @var mixed |
||
| 42 | */ |
||
| 43 | protected $customOrder; |
||
|
0 ignored issues
–
show
|
|||
| 44 | |||
| 45 | /** |
||
| 46 | * Comparator constructor. |
||
| 47 | * @param string $sortingOrder defines the order (ascending|descending) for a comparison |
||
| 48 | * @param mixed $customOrder |
||
| 49 | */ |
||
| 50 | 3 | public function __construct(string $sortingOrder = self::ORDER_ASC, $customOrder = null) |
|
| 51 | { |
||
| 52 | 3 | $this->sortingOrder = $sortingOrder; |
|
| 53 | 3 | $this->customOrder = $customOrder; |
|
| 54 | 3 | } |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first |
||
| 58 | * argument is less than, equal to, or greater than the second. |
||
| 59 | * |
||
| 60 | * @param Comparable $a |
||
| 61 | * @param Comparable $b |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | public abstract function compare(Comparable $a, Comparable $b): int; |
||
|
0 ignored issues
–
show
|
|||
| 65 | } |
||
| 66 |