12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Symfony\Component\CssSelector\Node;
- class Specificity
- {
- const A_FACTOR = 100;
- const B_FACTOR = 10;
- const C_FACTOR = 1;
- private $a;
- private $b;
- private $c;
-
- public function __construct($a, $b, $c)
- {
- $this->a = $a;
- $this->b = $b;
- $this->c = $c;
- }
-
- public function plus(self $specificity)
- {
- return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c);
- }
-
- public function getValue()
- {
- return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR;
- }
-
- public function compareTo(self $specificity)
- {
- if ($this->a !== $specificity->a) {
- return $this->a > $specificity->a ? 1 : -1;
- }
- if ($this->b !== $specificity->b) {
- return $this->b > $specificity->b ? 1 : -1;
- }
- if ($this->c !== $specificity->c) {
- return $this->c > $specificity->c ? 1 : -1;
- }
- return 0;
- }
- }
|