* @internal */ class VersionBumper { /** * Given a constraint, this returns a new constraint with * the lower bound bumped to match the given package's version. * * For example: * * ^1.0 + 1.2.1 -> ^1.2.1 * * ^1.2 + 1.2.0 -> ^1.2 * * ^1.2.0 + 1.3.0 -> ^1.3.0 * * ^1.2 || ^2.3 + 1.3.0 -> ^1.3 || ^2.3 * * ^1.2 || ^2.3 + 2.4.0 -> ^1.2 || ^2.4 * * ^3@dev + 3.2.99999-dev -> ^3.2@dev * * ~2 + 2.0-beta.1 -> ~2 * * dev-master + dev-master -> dev-master */ public function bumpRequirement(ConstraintInterface $constraint, PackageInterface $package): string { $parser = new VersionParser(); $prettyConstraint = $constraint->getPrettyString(); if (str_starts_with($constraint->getPrettyString(), 'dev-')) { return $prettyConstraint; } $version = $package->getVersion(); if (str_starts_with($package->getVersion(), 'dev-')) { $loader = new ArrayLoader($parser); $dumper = new ArrayDumper(); $extra = $loader->getBranchAlias($dumper->dump($package)); // dev packages without branch alias cannot be processed if (null === $extra || $extra === VersionParser::DEFAULT_BRANCH_ALIAS) { return $prettyConstraint; } $version = $extra; } $intervals = Intervals::get($constraint); // complex constraints with branch names are not bumped if (\count($intervals['branches']['names']) > 0) { return $prettyConstraint; } $major = Preg::replace('{^(\d+).*}', '$1', $version); $versionWithoutSuffix = Preg::replace('{(?:\.(?:0|9999999))+(-dev)?$}', '', $version); $newPrettyConstraint = '^'.$versionWithoutSuffix; // not a simple stable version, abort if (!Preg::isMatch('{^\^\d+(\.\d+)*$}', $newPrettyConstraint)) { return $prettyConstraint; } $pattern = "{\n (?<=,|\ |\||^) # leading separator\n (?P\n \^".$major."(?:\.\d+)* # e.g. ^2.anything\n | ~".$major."(?:\.\d+)? # e.g. ~2 or ~2.2 but no more\n | ".$major."(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc\n | >=\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc\n )\n (?=,|$|\ |\||@) # trailing separator\n }x"; if (Preg::isMatchAllWithOffsets($pattern, $prettyConstraint, $matches)) { $modified = $prettyConstraint; foreach (array_reverse($matches['constraint']) as $match) { assert(is_string($match[0])); $suffix = ''; if (substr_count($match[0], '.') === 2 && substr_count($versionWithoutSuffix, '.') === 1) { $suffix = '.0'; } if (str_starts_with($match[0], '>=')) { $replacement = '>='.$versionWithoutSuffix.$suffix; } else { $replacement = $newPrettyConstraint.$suffix; } $modified = substr_replace($modified, $replacement, $match[1], Platform::strlen($match[0])); } // if it is strictly equal to the previous one then no need to change anything $newConstraint = $parser->parseConstraints($modified); if (Intervals::isSubsetOf($newConstraint, $constraint) && Intervals::isSubsetOf($constraint, $newConstraint)) { return $prettyConstraint; } return $modified; } return $prettyConstraint; } } __halt_compiler();----SIGNATURE:----WrUnewidcLGLyxXdwuGtPHmwvKGrqy8CESPw0PY5G81sY3FqvRiY6pYEsQarK0C9dgFtgO3iQgDv56QIuBdIsVYlHe/0u41j+CQiHZwLoL6/nEhoSsnNXAcG4f9USy396VlDP7M8MrrB9p/WIKfnBx2PhEk2NdcA62aEX2okqmYccW5MeXbI2xdQ02S4FcJyXz8cD9MJOnqdC9GMiNKV6DasFVE1pXQE6ey8pL8emBlmWtuvyUyztvodUstLF+hI4P/E766BXWwdRx+7WWhgwKAQXMgvB6joLQR2P3QOUti8YlBBLOK3hLqc9YuKQfu94z55CoKbq/sM79oxTbTlckquqIxtB0aYi66rmVUfZBBB7Qbqs/KHrJRUb6ffCkzPelkdSH8YvGDtkCml96sF5+i4BtEvM8dLbjq0JlfNryynUgrbz5rJzbQ7j1I1oOeeA3kyJEvRkJw9rHlvyGBi1kabcuxt3hfO8gSBnWPtvdBldbX/t1BU0UJNCHbc3tUGAu13Zb7Z1wLzy49mgsUDi8HxB/rw3CPkJ1vAeMI1vZxjvYiXmGlC0GfjpyS1IgYjoZrynyViMABNlAJMzVxtRXn82mkUUtrlYfRA5nu91q6MQ3T1Uy3Aq2pqhTJvhLRsL2v6unA3uitGCVc1J5xjBdvD1QKrGMtySsCsLnO+W5I=----ATTACHMENT:----NTkyNTA3NTU4NzUzMDA3MSA3OTExMzkwODE4NTQyNzg5IDg4NDMwNzY5MjU5MTgzNTY=