4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\Node;
15 * Represents a node specificity.
17 * This component is a port of the Python cssselect library,
18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
20 * @see http://www.w3.org/TR/selectors/#specificity
22 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
41 public function __construct($a, $b, $c)
51 public function plus(Specificity $specificity)
53 return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c);
57 * Returns global specificity value.
61 public function getValue()
63 return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR;
67 * Returns -1 if the object specificity is lower than the argument,
68 * 0 if they are equal, and 1 if the argument is lower.
72 public function compareTo(Specificity $specificity)
74 if ($this->a !== $specificity->a) {
75 return $this->a > $specificity->a ? 1 : -1;
78 if ($this->b !== $specificity->b) {
79 return $this->b > $specificity->b ? 1 : -1;
82 if ($this->c !== $specificity->c) {
83 return $this->c > $specificity->c ? 1 : -1;