AbstractNode.php
2 years ago
AttributeNode.php
2 years ago
ClassNode.php
2 years ago
CombinedSelectorNode.php
2 years ago
ElementNode.php
2 years ago
FunctionNode.php
2 years ago
HashNode.php
2 years ago
NegationNode.php
2 years ago
NodeInterface.php
2 years ago
PseudoNode.php
2 years ago
SelectorNode.php
2 years ago
Specificity.php
2 years ago
index.php
2 years ago
Specificity.php
40 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Node; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class Specificity |
| 5 | { |
| 6 | public const A_FACTOR = 100; |
| 7 | public const B_FACTOR = 10; |
| 8 | public const C_FACTOR = 1; |
| 9 | private $a; |
| 10 | private $b; |
| 11 | private $c; |
| 12 | public function __construct(int $a, int $b, int $c) |
| 13 | { |
| 14 | $this->a = $a; |
| 15 | $this->b = $b; |
| 16 | $this->c = $c; |
| 17 | } |
| 18 | public function plus(self $specificity) : self |
| 19 | { |
| 20 | return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c); |
| 21 | } |
| 22 | public function getValue() : int |
| 23 | { |
| 24 | return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR; |
| 25 | } |
| 26 | public function compareTo(self $specificity) : int |
| 27 | { |
| 28 | if ($this->a !== $specificity->a) { |
| 29 | return $this->a > $specificity->a ? 1 : -1; |
| 30 | } |
| 31 | if ($this->b !== $specificity->b) { |
| 32 | return $this->b > $specificity->b ? 1 : -1; |
| 33 | } |
| 34 | if ($this->c !== $specificity->c) { |
| 35 | return $this->c > $specificity->c ? 1 : -1; |
| 36 | } |
| 37 | return 0; |
| 38 | } |
| 39 | } |
| 40 |