function Constraint::versionCompare
@phpstan-param self::STR_OP_* $operator
Parameters
string $a:
string $b:
string $operator:
bool $compareBranches:
Return value
bool
Throws
\InvalidArgumentException if invalid operator is given.
1 call to Constraint::versionCompare()
- Constraint::matchSpecific in vendor/
composer/ semver/ src/ Constraint/ Constraint.php
File
-
vendor/
composer/ semver/ src/ Constraint/ Constraint.php, line 200
Class
- Constraint
- Defines a constraint.
Namespace
Composer\Semver\ConstraintCode
public function versionCompare($a, $b, $operator, $compareBranches = false) {
if (!isset(self::$transOpStr[$operator])) {
throw new \InvalidArgumentException(sprintf('Invalid operator "%s" given, expected one of: %s', $operator, implode(', ', self::getSupportedOperators())));
}
$aIsBranch = strpos($a, 'dev-') === 0;
$bIsBranch = strpos($b, 'dev-') === 0;
if ($operator === '!=' && ($aIsBranch || $bIsBranch)) {
return $a !== $b;
}
if ($aIsBranch && $bIsBranch) {
return $operator === '==' && $a === $b;
}
// when branches are not comparable, we make sure dev branches never match anything
if (!$compareBranches && ($aIsBranch || $bIsBranch)) {
return false;
}
return \version_compare($a, $b, $operator);
}