*/ class MultiConstraint extends SemverMultiConstraint { /** * Tries to optimize the constraints as much as possible, meaning * reducing/collapsing congruent constraints etc. * Does not necessarily return a MultiConstraint instance if * things can be reduced to a simple constraint * * @param ConstraintInterface[] $constraints A set of constraints * @param bool $conjunctive Whether the constraints should be treated as conjunctive or disjunctive * * @return ConstraintInterface */ public static function create(array $constraints, $conjunctive = true) { if (\count($constraints) === 0) { // EmptyConstraint only exists in composer 1.x. Configure as to run phan against composer 2.x // @phan-suppress-next-line PhanTypeMismatchReturn, PhanUndeclaredClassMethod return new EmptyConstraint(); } if (\count($constraints) === 1) { return $constraints[0]; } $optimized = self::optimizeConstraints($constraints, $conjunctive); if ($optimized !== null) { list($constraints, $conjunctive) = $optimized; if (\count($constraints) === 1) { return $constraints[0]; } } return new self($constraints, $conjunctive); } /** * @return array|null */ private static function optimizeConstraints(array $constraints, $conjunctive) { // parse the two OR groups and if they are contiguous we collapse // them into one constraint // [>= 1 < 2] || [>= 2 < 3] || [>= 3 < 4] => [>= 1 < 4] if (!$conjunctive) { $left = $constraints[0]; $mergedConstraints = []; $optimized = false; for ($i = 1, $l = \count($constraints); $i < $l; $i++) { $right = $constraints[$i]; if ($left instanceof SemverMultiConstraint && $left->conjunctive && $right instanceof SemverMultiConstraint && $right->conjunctive && \count($left->constraints) === 2 && \count($right->constraints) === 2 && ($left0 = (string) $left->constraints[0]) && $left0[0] === '>' && $left0[1] === '=' && ($left1 = (string) $left->constraints[1]) && $left1[0] === '<' && ($right0 = (string) $right->constraints[0]) && $right0[0] === '>' && $right0[1] === '=' && ($right1 = (string) $right->constraints[1]) && $right1[0] === '<' && substr($left1, 2) === substr($right0, 3) ) { $optimized = true; $left = new MultiConstraint( [ $left->constraints[0], $right->constraints[1], ], true ); } else { $mergedConstraints[] = $left; $left = $right; } } if ($optimized) { $mergedConstraints[] = $left; return [$mergedConstraints, false]; } } // TODO: Here's the place to put more optimizations return null; } } __halt_compiler();----SIGNATURE:----uCiZbs17KhhepyeP+JHzfuIR5Sm+c7yYHwUkLcvWpREZ8ZdZxgK/BqQH4c+dA44mE8njDKIUGKn4mBc5Xv43mW3HdXdDIruLgt4Oy4UeQNmMFNEn3jOKnjzOuGFsZPgDA9yZLAqM5zrxuPJLoQRw3IOJRHTNohSi4xXDwinFWikgBE+uVi39GmHn6IfIW5jw+EPxLQbyQ0uKoIGZlaERsVU77pxwPsv7h7WLqPQQTtVIFq0gfWcyg4Jv9/TWNvLYesChQY7+yosuc1pqFOhyjnpaYBuv/SXBS5wE0Nnpl9RVSagSSE/JpVMiXk1XDJDknNKU8QP9wohJPg06GotP775naPfPkp2vl5RWdn5M00ZPYkn6TBRo2mRxEeEPoiY+SlEHEDjArbqQkrwA0gDzYns5jHdAqVIrEPlWMq6l8/ToQOFvOReSKFdq1jG6Z0j+cdnFxRQaJz60MLbtW0s3JVnuLtJiNDuxjesJ+ayx+O72pAbTWrRG5IAHezDsxPKmXrAWWPHobQlWKK35jok2WdoREHF5Ur4A2QcQouk3CviiOMgdWTvlY2iehEB9BFmuwSWx87i/ZjYl86eywtCb7UVi9mN0E3K3NfIw9jUcQUt3GEE/anadH0wA31NBe/MvY12lRHxBcHQaJSCwMLkSUFTvbiPz9UEeqG6gRDYgLZQ=----ATTACHMENT:----MTYyMjMzMDkwNDE5MDkwOCA5MzU1MzU0MjUwMjA0NjE0IDkwMTg0NjI2MTg4ODM4ODI=