1 | <?php |
||
28 | final class HyphenatedRangeParser implements RangeParserInterface |
||
29 | { |
||
30 | use ChunkBySeparator; |
||
31 | |||
32 | /** @var VersionParser */ |
||
33 | private $versionParser; |
||
34 | |||
35 | /** @var ComparatorInterface */ |
||
36 | private $greaterOrEqualTo; |
||
37 | |||
38 | /** @var ComparatorInterface */ |
||
39 | private $lessThan; |
||
40 | |||
41 | /** @var ComparatorInterface */ |
||
42 | private $lessOrEqualTo; |
||
43 | |||
44 | /** @var string[][] */ |
||
45 | private $validConfigurations = [ |
||
46 | [Token::DIGITS, Token::DIGITS], |
||
47 | [Token::DIGITS, Token::LABEL_STRING, Token::DIGITS], |
||
48 | [Token::DIGITS, Token::DIGITS, Token::LABEL_STRING], |
||
49 | [Token::DIGITS, Token::LABEL_STRING, Token::DIGITS, Token::LABEL_STRING] |
||
50 | ]; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Constructor. |
||
55 | * |
||
56 | * @param VersionParser $versionParser |
||
57 | * @param ComparatorInterface $greaterOrEqualTo |
||
58 | * @param ComparatorInterface $lessThan |
||
59 | * @param ComparatorInterface $lessOrEqualTo |
||
60 | */ |
||
61 | 11 | public function __construct( |
|
72 | |||
73 | /** |
||
74 | * Returns true if the token list can be parsed as a hyphenated range. |
||
75 | * |
||
76 | * @param Token[] $tokenList |
||
77 | * |
||
78 | * @return boolean |
||
79 | */ |
||
80 | 11 | public function canParse(array $tokenList) |
|
95 | |||
96 | /** |
||
97 | * Build a ComparatorVersion representing the hyphenated range. |
||
98 | * |
||
99 | * @param Token[] $tokenList |
||
100 | * |
||
101 | * @return VersionRangeInterface |
||
102 | */ |
||
103 | 10 | public function parse(array $tokenList) |
|
121 | |||
122 | /** |
||
123 | * Chunk a token list by the dash seperator, returning array of token lists omitting the seperator tokens. |
||
124 | * |
||
125 | * @param Token[] $tokenList |
||
126 | * @return Token[][] |
||
127 | */ |
||
128 | 11 | private function chunkByDash(array $tokenList) |
|
137 | |||
138 | /** |
||
139 | * Returns an array of token arrays, the first is tokens for the lower bound and the second is the upper bound. |
||
140 | * |
||
141 | * @param Token[][] $chunkedList |
||
142 | * |
||
143 | * @return Token[][] |
||
144 | */ |
||
145 | 11 | private function getSingleVersionTokens( |
|
180 | |||
181 | /** |
||
182 | * Returns true if the chunks match the configuration. |
||
183 | * |
||
184 | * @param Token[][] $chunkedList |
||
185 | * @param string[] $configuration |
||
186 | * |
||
187 | * @return boolean |
||
188 | */ |
||
189 | 11 | private function chunksMatchConfiguration( |
|
203 | |||
204 | /** |
||
205 | * Get the upper version constraint from a token list. |
||
206 | * |
||
207 | * @param Token[] $tokenList |
||
208 | * |
||
209 | * @return ComparatorVersion |
||
210 | */ |
||
211 | 6 | private function getUpperConstraint(array $tokenList) |
|
232 | } |
||
233 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.