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

Breadcrumb

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

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\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 = 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);
}

API Navigation

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