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

Breadcrumb

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

class Rule2Literals

@author Nils Adermann <naderman@naderman.de> @phpstan-import-type ReasonData from Rule

Hierarchy

  • class \Composer\DependencyResolver\Rule
    • class \Composer\DependencyResolver\Rule2Literals extends \Composer\DependencyResolver\Rule

Expanded class hierarchy of Rule2Literals

File

vendor/composer/composer/src/Composer/DependencyResolver/Rule2Literals.php, line 19

Namespace

Composer\DependencyResolver
View source
class Rule2Literals extends Rule {
    
    /** @var int */
    protected $literal1;
    
    /** @var int */
    protected $literal2;
    
    /**
     * @param Rule::RULE_* $reason A RULE_* constant
     * @param mixed $reasonData
     *
     * @phpstan-param ReasonData $reasonData
     */
    public function __construct(int $literal1, int $literal2, $reason, $reasonData) {
        parent::__construct($reason, $reasonData);
        if ($literal1 < $literal2) {
            $this->literal1 = $literal1;
            $this->literal2 = $literal2;
        }
        else {
            $this->literal1 = $literal2;
            $this->literal2 = $literal1;
        }
    }
    
    /**
     * @return non-empty-list<int>
     */
    public function getLiterals() : array {
        return [
            $this->literal1,
            $this->literal2,
        ];
    }
    
    /**
     * @inheritDoc
     */
    public function getHash() {
        return $this->literal1 . ',' . $this->literal2;
    }
    
    /**
     * Checks if this rule is equal to another one
     *
     * Ignores whether either of the rules is disabled.
     *
     * @param  Rule $rule The rule to check against
     * @return bool Whether the rules are equal
     */
    public function equals(Rule $rule) : bool {
        // specialized fast-case
        if ($rule instanceof self) {
            if ($this->literal1 !== $rule->literal1) {
                return false;
            }
            if ($this->literal2 !== $rule->literal2) {
                return false;
            }
            return true;
        }
        $literals = $rule->getLiterals();
        if (2 !== \count($literals)) {
            return false;
        }
        if ($this->literal1 !== $literals[0]) {
            return false;
        }
        if ($this->literal2 !== $literals[1]) {
            return false;
        }
        return true;
    }
    
    /** @return false */
    public function isAssertion() : bool {
        return false;
    }
    
    /**
     * Formats a rule as a string of the format (Literal1|Literal2|...)
     */
    public function __toString() : string {
        $result = $this->isDisabled() ? 'disabled(' : '(';
        $result .= $this->literal1 . '|' . $this->literal2 . ')';
        return $result;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Rule2Literals::$literal1 protected property @var int
Rule2Literals::$literal2 protected property @var int
Rule2Literals::equals public function Checks if this rule is equal to another one Overrides Rule::equals
Rule2Literals::getHash public function @inheritDoc Overrides Rule::getHash
Rule2Literals::getLiterals public function Overrides Rule::getLiterals
Rule2Literals::isAssertion public function Overrides Rule::isAssertion
Rule2Literals::__construct public function @phpstan-param ReasonData $reasonData Overrides Rule::__construct
Rule2Literals::__toString public function Formats a rule as a string of the format (Literal1|Literal2|...) Overrides Rule::__toString
Rule::$bitfield protected property @var int
Rule::$reasonData protected property @phpstan-var ReasonData
Rule::$request protected property @var Request
Rule::BITFIELD_DISABLED private constant
Rule::BITFIELD_REASON private constant
Rule::BITFIELD_TYPE private constant
Rule::deduplicateDefaultBranchAlias private function
Rule::disable public function 1
Rule::enable public function
Rule::formatPackagesUnique protected function
Rule::getPrettyString public function
Rule::getReason public function
Rule::getReasonData public function @phpstan-return ReasonData
Rule::getRequiredPackage public function
Rule::getSourcePackage public function @internal
Rule::getType public function
Rule::isCausedByLock public function
Rule::isDisabled public function
Rule::isEnabled public function
Rule::RULE_FIXED public constant
Rule::RULE_LEARNED public constant
Rule::RULE_PACKAGE_ALIAS public constant
Rule::RULE_PACKAGE_CONFLICT public constant
Rule::RULE_PACKAGE_INVERSE_ALIAS public constant
Rule::RULE_PACKAGE_REQUIRES public constant
Rule::RULE_PACKAGE_SAME_NAME public constant
Rule::RULE_ROOT_REQUIRE public constant
Rule::setType public function

API Navigation

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