1 | <?php |
||
18 | class StatementRank { |
||
19 | |||
20 | /** |
||
21 | * Higher values are more preferred. |
||
22 | * TODO: Link to discussion/documentation that guarantees increasing order. |
||
23 | */ |
||
24 | const DEPRECATED = 0; |
||
25 | const NORMAL = 1; |
||
26 | const PREFERRED = 2; |
||
27 | |||
28 | private static $names = [ |
||
29 | self::DEPRECATED => 'deprecated', |
||
30 | self::NORMAL => 'normal', |
||
31 | self::PREFERRED => 'preferred', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @return string[] Array mapping all known self::... constants (integers) to string names. |
||
36 | */ |
||
37 | public static function getNames() { |
||
40 | |||
41 | /** |
||
42 | * @return int[] Array mapping string names to all known self::... constants (integers). |
||
43 | */ |
||
44 | public static function getAllRanks() { |
||
47 | |||
48 | /** |
||
49 | * @param int $rank |
||
50 | * |
||
51 | * @throws InvalidArgumentException |
||
52 | */ |
||
53 | public static function assertIsValid( $rank ) { |
||
58 | |||
59 | /** |
||
60 | * @param int $rank |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public static function isValid( $rank ) { |
||
67 | |||
68 | /** |
||
69 | * @param int $rank |
||
70 | * |
||
71 | * @throws InvalidArgumentException |
||
72 | * @return bool Statements with a deprecated (or lower) rank are known to be false. But don't be |
||
73 | * fooled, this does not mean higher ranks are known to be true! |
||
74 | */ |
||
75 | public static function isFalse( $rank ) { |
||
80 | |||
81 | /** |
||
82 | * @param int|null $rank1 |
||
83 | * @param int|null $rank2 |
||
84 | * |
||
85 | * @throws InvalidArgumentException |
||
86 | * @return bool True if the given ranks are equal. |
||
87 | */ |
||
88 | public static function isEqual( $rank1, $rank2 ) { |
||
91 | |||
92 | /** |
||
93 | * @param int|null $rank1 |
||
94 | * @param int|null $rank2 |
||
95 | * |
||
96 | * @throws InvalidArgumentException |
||
97 | * @return bool True if the first rank is less preferred than the second. |
||
98 | */ |
||
99 | public static function isLower( $rank1, $rank2 ) { |
||
102 | |||
103 | /** |
||
104 | * @param int|null $rank1 |
||
105 | * @param int|null $rank2 |
||
106 | * |
||
107 | * @throws InvalidArgumentException |
||
108 | * @return bool True if the first rank is more preferred than the second. |
||
109 | */ |
||
110 | public static function isHigher( $rank1, $rank2 ) { |
||
113 | |||
114 | /** |
||
115 | * @param int|null $rank1 |
||
116 | * @param int|null $rank2 |
||
117 | * |
||
118 | * @throws InvalidArgumentException |
||
119 | * @return int 0 if the ranks are equal, -1 if the first rank is less preferred than the second, |
||
120 | * or +1 if the first rank is more preferred than the second. |
||
121 | */ |
||
122 | public static function compare( $rank1, $rank2 ) { |
||
138 | |||
139 | /** |
||
140 | * @param int[]|int $ranks |
||
141 | * @param int [$rank2,...] |
||
142 | * |
||
143 | * @return int|null Best rank in the array or list of arguments, or null if none given. |
||
144 | */ |
||
145 | public static function findBestRank( $ranks = [] /*...*/ ) { |
||
164 | |||
165 | } |
||
166 |