Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Bound.php

function Bound::compareTo

Compares a bound to another with a given operator.

Parameters

Bound $other:

string $operator:

Return value

bool

File

vendor/composer/semver/src/Constraint/Bound.php, line 76

Class

Bound

Namespace

Composer\Semver\Constraint

Code

public function compareTo(Bound $other, $operator) {
    if (!\in_array($operator, array(
        '<',
        '>',
    ), true)) {
        throw new \InvalidArgumentException('Does not support any other operator other than > or <.');
    }
    // If they are the same it doesn't matter
    if ($this == $other) {
        return false;
    }
    $compareResult = version_compare($this->getVersion(), $other->getVersion());
    // Not the same version means we don't need to check if the bounds are inclusive or not
    if (0 !== $compareResult) {
        return ('>' === $operator ? 1 : -1) === $compareResult;
    }
    // Question we're answering here is "am I higher than $other?"
    return '>' === $operator ? $other->isInclusive() : !$other->isInclusive();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal