123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?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(Specificity $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(Specificity $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;
- }
- }
|