1 | <?php |
||
14 | class Specificity |
||
15 | { |
||
16 | /** |
||
17 | * The number of ID selectors in the selector |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | private $a; |
||
22 | |||
23 | /** |
||
24 | * The number of class selectors, attributes selectors, and pseudo-classes in the selector |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | private $b; |
||
29 | |||
30 | /** |
||
31 | * The number of type selectors and pseudo-elements in the selector |
||
32 | * |
||
33 | * @var int |
||
34 | */ |
||
35 | private $c; |
||
36 | |||
37 | /** |
||
38 | * @param int $a The number of ID selectors in the selector |
||
39 | * @param int $b The number of class selectors, attributes selectors, and pseudo-classes in the selector |
||
40 | * @param int $c The number of type selectors and pseudo-elements in the selector |
||
41 | */ |
||
42 | 52 | public function __construct($a = 0, $b = 0, $c = 0) |
|
48 | |||
49 | /** |
||
50 | * Increase the current specificity by adding the three values |
||
51 | * |
||
52 | * @param int $a The number of ID selectors in the selector |
||
53 | * @param int $b The number of class selectors, attributes selectors, and pseudo-classes in the selector |
||
54 | * @param int $c The number of type selectors and pseudo-elements in the selector |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | 1 | public function increase($a, $b, $c) |
|
64 | |||
65 | /** |
||
66 | * Get the specificity values as an array |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 10 | public function getValues(): array |
|
74 | |||
75 | /** |
||
76 | * Calculate the specificity based on a CSS Selector string, |
||
77 | * Based on the patterns from premailer/css_parser by Alex Dunae |
||
78 | * |
||
79 | * @see https://github.com/premailer/css_parser/blob/master/lib/css_parser/regexps.rb |
||
80 | * |
||
81 | * @param string $selector |
||
82 | * |
||
83 | * @return static |
||
84 | */ |
||
85 | 50 | public static function fromSelector(string $selector) |
|
120 | |||
121 | /** |
||
122 | * Returns <0 when $specificity is greater, 0 when equal, >0 when smaller |
||
123 | * |
||
124 | * @param Specificity $specificity |
||
125 | * |
||
126 | * @return int |
||
127 | */ |
||
128 | 34 | public function compareTo(self $specificity): int |
|
140 | } |
||
141 |