You are here

public function Constraint::versionCompare in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/composer/semver/src/Constraint/Constraint.php \Composer\Semver\Constraint\Constraint::versionCompare()

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 105

Class

Constraint
Defines a constraint.

Namespace

Composer\Semver\Constraint

Code

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 = 'dev-' === substr($a, 0, 4);
  $bIsBranch = 'dev-' === substr($b, 0, 4);
  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);
}