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

Breadcrumb

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

function DefaultPolicy::versionCompare

@phpstan-param Constraint::STR_OP_* $operator

Parameters

string $operator One of Constraint::STR_OP_*:

Overrides PolicyInterface::versionCompare

1 call to DefaultPolicy::versionCompare()
DefaultPolicy::pruneToBestVersion in vendor/composer/composer/src/Composer/DependencyResolver/DefaultPolicy.php

File

vendor/composer/composer/src/Composer/DependencyResolver/DefaultPolicy.php, line 53

Class

DefaultPolicy
@author Nils Adermann <naderman@naderman.de> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\DependencyResolver

Code

public function versionCompare(PackageInterface $a, PackageInterface $b, string $operator) : bool {
    if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
        return BasePackage::STABILITIES[$stabA] < BasePackage::STABILITIES[$stabB];
    }
    // dev versions need to be compared as branches via matchSpecific's special treatment, the rest can be optimized with compiling matcher
    if ($a->isDev() && str_starts_with($a->getVersion(), 'dev-') || $b->isDev() && str_starts_with($b->getVersion(), 'dev-')) {
        $constraint = new Constraint($operator, $b->getVersion());
        $version = new Constraint('==', $a->getVersion());
        return $constraint->matchSpecific($version, true);
    }
    return CompilingMatcher::match(new Constraint($operator, $b->getVersion()), Constraint::OP_EQ, $a->getVersion());
}

API Navigation

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