@@ -69,11 +69,6 @@ class Selector
6969 */
7070 private $ selector ;
7171
72- /**
73- * @var int|null
74- */
75- private $ specificity ;
76-
7772 /**
7873 * @param string $selector
7974 *
@@ -91,9 +86,6 @@ public static function isValid($selector)
9186 public function __construct ($ selector , $ calculateSpecificity = false )
9287 {
9388 $ this ->setSelector ($ selector );
94- if ($ calculateSpecificity ) {
95- $ this ->getSpecificity ();
96- }
9789 }
9890
9991 /**
@@ -110,7 +102,6 @@ public function getSelector()
110102 public function setSelector ($ selector ): void
111103 {
112104 $ this ->selector = \trim ($ selector );
113- $ this ->specificity = null ;
114105 }
115106
116107 /**
@@ -122,19 +113,16 @@ public function __toString(): string
122113 }
123114
124115 /**
125- * @return int
116+ * @return int<0, max>
126117 */
127- public function getSpecificity ()
118+ public function getSpecificity (): int
128119 {
129- if ($ this ->specificity === null ) {
130- $ a = 0 ;
131- /// @todo should exclude \# as well as "#"
132- $ aMatches = null ;
133- $ b = \substr_count ($ this ->selector , '# ' );
134- $ c = \preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->selector , $ aMatches );
135- $ d = \preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->selector , $ aMatches );
136- $ this ->specificity = ($ a * 1000 ) + ($ b * 100 ) + ($ c * 10 ) + $ d ;
137- }
138- return $ this ->specificity ;
120+ $ a = 0 ;
121+ /// @todo should exclude \# as well as "#"
122+ $ aMatches = null ;
123+ $ b = \substr_count ($ this ->selector , '# ' );
124+ $ c = \preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->selector , $ aMatches );
125+ $ d = \preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->selector , $ aMatches );
126+ return ($ a * 1000 ) + ($ b * 100 ) + ($ c * 10 ) + $ d ;
139127 }
140128}
0 commit comments