You are here

public function Constraint::matchSpecific in Automatic Updates 7

Parameters

Constraint $provider:

bool $compareBranches:

Return value

bool

1 call to Constraint::matchSpecific()
Constraint::matches in vendor/composer/semver/src/Constraint/Constraint.php

File

vendor/composer/semver/src/Constraint/Constraint.php, line 174

Class

Constraint
Defines a constraint.

Namespace

Composer\Semver\Constraint

Code

public function matchSpecific(Constraint $provider, $compareBranches = false) {
  $noEqualOp = str_replace('=', '', self::$transOpInt[$this->operator]);
  $providerNoEqualOp = str_replace('=', '', self::$transOpInt[$provider->operator]);
  $isEqualOp = self::OP_EQ === $this->operator;
  $isNonEqualOp = self::OP_NE === $this->operator;
  $isProviderEqualOp = self::OP_EQ === $provider->operator;
  $isProviderNonEqualOp = self::OP_NE === $provider->operator;

  // '!=' operator is match when other operator is not '==' operator or version is not match
  // these kinds of comparisons always have a solution
  if ($isNonEqualOp || $isProviderNonEqualOp) {
    return !$isEqualOp && !$isProviderEqualOp || $this
      ->versionCompare($provider->version, $this->version, '!=', $compareBranches);
  }

  // an example for the condition is <= 2.0 & < 1.0
  // these kinds of comparisons always have a solution
  if ($this->operator !== self::OP_EQ && $noEqualOp === $providerNoEqualOp) {
    return true;
  }
  if ($this
    ->versionCompare($provider->version, $this->version, self::$transOpInt[$this->operator], $compareBranches)) {

    // special case, e.g. require >= 1.0 and provide < 1.0
    // 1.0 >= 1.0 but 1.0 is outside of the provided interval
    return !($provider->version === $this->version && self::$transOpInt[$provider->operator] === $providerNoEqualOp && self::$transOpInt[$this->operator] !== $noEqualOp);
  }
  return false;
}