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

Breadcrumb

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

class MultiConflictRule

@author Nils Adermann <naderman@naderman.de>

MultiConflictRule([A, B, C]) acts as Rule([-A, -B]), Rule([-A, -C]), Rule([-B, -C])

Hierarchy

  • class \Composer\DependencyResolver\Rule
    • class \Composer\DependencyResolver\MultiConflictRule extends \Composer\DependencyResolver\Rule

Expanded class hierarchy of MultiConflictRule

File

vendor/composer/composer/src/Composer/DependencyResolver/MultiConflictRule.php, line 20

Namespace

Composer\DependencyResolver
View source
class MultiConflictRule extends Rule {
    
    /** @var non-empty-list<int> */
    protected $literals;
    
    /**
     * @param non-empty-list<int> $literals
     */
    public function __construct(array $literals, $reason, $reasonData) {
        parent::__construct($reason, $reasonData);
        if (\count($literals) < 3) {
            throw new \RuntimeException("multi conflict rule requires at least 3 literals");
        }
        // sort all packages ascending by id
        sort($literals);
        $this->literals = $literals;
    }
    
    /**
     * @return non-empty-list<int>
     */
    public function getLiterals() : array {
        return $this->literals;
    }
    
    /**
     * @inheritDoc
     */
    public function getHash() {
        $data = unpack('ihash', (string) hash(\PHP_VERSION_ID > 80100 ? 'xxh3' : 'sha1', 'c:' . implode(',', $this->literals), true));
        if (false === $data) {
            throw new \RuntimeException('Failed unpacking: ' . implode(', ', $this->literals));
        }
        return $data['hash'];
    }
    
    /**
     * 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 {
        if ($rule instanceof MultiConflictRule) {
            return $this->literals === $rule->getLiterals();
        }
        return false;
    }
    public function isAssertion() : bool {
        return false;
    }
    
    /**
     * @return never
     * @throws \RuntimeException
     */
    public function disable() : void {
        throw new \RuntimeException("Disabling multi conflict rules is not possible. Please contact composer at https://github.com/composer/composer to let us debug what lead to this situation.");
    }
    
    /**
     * Formats a rule as a string of the format (Literal1|Literal2|...)
     */
    public function __toString() : string {
        // TODO multi conflict?
        $result = $this->isDisabled() ? 'disabled(multi(' : '(multi(';
        foreach ($this->literals as $i => $literal) {
            if ($i !== 0) {
                $result .= '|';
            }
            $result .= $literal;
        }
        $result .= '))';
        return $result;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
MultiConflictRule::$literals protected property @var non-empty-list&lt;int&gt;
MultiConflictRule::disable public function Overrides Rule::disable
MultiConflictRule::equals public function Checks if this rule is equal to another one Overrides Rule::equals
MultiConflictRule::getHash public function @inheritDoc Overrides Rule::getHash
MultiConflictRule::getLiterals public function Overrides Rule::getLiterals
MultiConflictRule::isAssertion public function Overrides Rule::isAssertion
MultiConflictRule::__construct public function Overrides Rule::__construct
MultiConflictRule::__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::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