| Conditions | 32 |
| Paths | 1344 |
| Total Lines | 105 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 174 | private static function generateIntervals(ConstraintInterface $constraint, $stopOnFirstValidInterval = \false) |
||
| 175 | { |
||
| 176 | if ($constraint instanceof MatchAllConstraint) { |
||
| 177 | return array('numeric' => array(new Interval(Interval::fromZero(), Interval::untilPositiveInfinity())), 'branches' => Interval::anyDev()); |
||
| 178 | } |
||
| 179 | if ($constraint instanceof MatchNoneConstraint) { |
||
| 180 | return array('numeric' => array(), 'branches' => array('names' => array(), 'exclude' => \false)); |
||
| 181 | } |
||
| 182 | if ($constraint instanceof Constraint) { |
||
| 183 | return self::generateSingleConstraintIntervals($constraint); |
||
| 184 | } |
||
| 185 | if (!$constraint instanceof MultiConstraint) { |
||
| 186 | throw new \UnexpectedValueException('The constraint passed in should be an MatchAllConstraint, Constraint or MultiConstraint instance, got ' . \get_class($constraint) . '.'); |
||
| 187 | } |
||
| 188 | $constraints = $constraint->getConstraints(); |
||
| 189 | $numericGroups = array(); |
||
| 190 | $constraintBranches = array(); |
||
| 191 | foreach ($constraints as $c) { |
||
| 192 | $res = self::get($c); |
||
| 193 | $numericGroups[] = $res['numeric']; |
||
| 194 | $constraintBranches[] = $res['branches']; |
||
| 195 | } |
||
| 196 | if ($constraint->isDisjunctive()) { |
||
| 197 | $branches = Interval::noDev(); |
||
| 198 | foreach ($constraintBranches as $b) { |
||
| 199 | if ($b['exclude']) { |
||
| 200 | if ($branches['exclude']) { |
||
| 201 | $branches['names'] = \array_intersect($branches['names'], $b['names']); |
||
| 202 | } else { |
||
| 203 | $branches['exclude'] = \true; |
||
| 204 | $branches['names'] = \array_diff($b['names'], $branches['names']); |
||
| 205 | } |
||
| 206 | } else { |
||
| 207 | if ($branches['exclude']) { |
||
| 208 | $branches['names'] = \array_diff($branches['names'], $b['names']); |
||
| 209 | } else { |
||
| 210 | $branches['names'] = \array_merge($branches['names'], $b['names']); |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | } else { |
||
| 215 | $branches = Interval::anyDev(); |
||
| 216 | foreach ($constraintBranches as $b) { |
||
| 217 | if ($b['exclude']) { |
||
| 218 | if ($branches['exclude']) { |
||
| 219 | $branches['names'] = \array_merge($branches['names'], $b['names']); |
||
| 220 | } else { |
||
| 221 | $branches['names'] = \array_diff($branches['names'], $b['names']); |
||
| 222 | } |
||
| 223 | } else { |
||
| 224 | if ($branches['exclude']) { |
||
| 225 | $branches['names'] = \array_diff($b['names'], $branches['names']); |
||
| 226 | $branches['exclude'] = \false; |
||
| 227 | } else { |
||
| 228 | $branches['names'] = \array_intersect($branches['names'], $b['names']); |
||
| 229 | } |
||
| 230 | } |
||
| 231 | } |
||
| 232 | } |
||
| 233 | $branches['names'] = \array_unique($branches['names']); |
||
| 234 | if (\count($numericGroups) === 1) { |
||
| 235 | return array('numeric' => $numericGroups[0], 'branches' => $branches); |
||
| 236 | } |
||
| 237 | $borders = array(); |
||
| 238 | foreach ($numericGroups as $group) { |
||
| 239 | foreach ($group as $interval) { |
||
| 240 | $borders[] = array('version' => $interval->getStart()->getVersion(), 'operator' => $interval->getStart()->getOperator(), 'side' => 'start'); |
||
| 241 | $borders[] = array('version' => $interval->getEnd()->getVersion(), 'operator' => $interval->getEnd()->getOperator(), 'side' => 'end'); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | $opSortOrder = self::$opSortOrder; |
||
| 245 | \usort($borders, function ($a, $b) use($opSortOrder) { |
||
| 246 | $order = \version_compare($a['version'], $b['version']); |
||
| 247 | if ($order === 0) { |
||
| 248 | return $opSortOrder[$a['operator']] - $opSortOrder[$b['operator']]; |
||
| 249 | } |
||
| 250 | return $order; |
||
| 251 | }); |
||
| 252 | $activeIntervals = 0; |
||
| 253 | $intervals = array(); |
||
| 254 | $index = 0; |
||
| 255 | $activationThreshold = $constraint->isConjunctive() ? \count($numericGroups) : 1; |
||
| 256 | $start = null; |
||
| 257 | foreach ($borders as $border) { |
||
| 258 | if ($border['side'] === 'start') { |
||
| 259 | $activeIntervals++; |
||
| 260 | } else { |
||
| 261 | $activeIntervals--; |
||
| 262 | } |
||
| 263 | if (!$start && $activeIntervals >= $activationThreshold) { |
||
| 264 | $start = new Constraint($border['operator'], $border['version']); |
||
| 265 | } elseif ($start && $activeIntervals < $activationThreshold) { |
||
| 266 | if (\version_compare($start->getVersion(), $border['version'], '=') && ($start->getOperator() === '>' && $border['operator'] === '<=' || $start->getOperator() === '>=' && $border['operator'] === '<')) { |
||
| 267 | unset($intervals[$index]); |
||
| 268 | } else { |
||
| 269 | $intervals[$index] = new Interval($start, new Constraint($border['operator'], $border['version'])); |
||
|
|
|||
| 270 | $index++; |
||
| 271 | if ($stopOnFirstValidInterval) { |
||
| 272 | break; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | $start = null; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | return array('numeric' => $intervals, 'branches' => $branches); |
||
| 279 | } |
||
| 309 |