@@ -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 *
@@ -93,9 +88,6 @@ public static function isValid($selector)
9388 public function __construct ($ selector , $ calculateSpecificity = false )
9489 {
9590 $ this ->setSelector ($ selector );
96- if ($ calculateSpecificity ) {
97- $ this ->getSpecificity ();
98- }
9991 }
10092
10193 /**
@@ -112,7 +104,6 @@ public function getSelector()
112104 public function setSelector ($ selector ): void
113105 {
114106 $ this ->selector = \trim ($ selector );
115- $ this ->specificity = null ;
116107 }
117108
118109 /**
@@ -124,19 +115,16 @@ public function __toString(): string
124115 }
125116
126117 /**
127- * @return int
118+ * @return int<0, max>
128119 */
129- public function getSpecificity ()
120+ public function getSpecificity (): int
130121 {
131- if ($ this ->specificity === null ) {
132- $ a = 0 ;
133- /// @todo should exclude \# as well as "#"
134- $ aMatches = null ;
135- $ b = \substr_count ($ this ->selector , '# ' );
136- $ c = \preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->selector , $ aMatches );
137- $ d = \preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->selector , $ aMatches );
138- $ this ->specificity = ($ a * 1000 ) + ($ b * 100 ) + ($ c * 10 ) + $ d ;
139- }
140- return $ this ->specificity ;
122+ $ a = 0 ;
123+ /// @todo should exclude \# as well as "#"
124+ $ aMatches = null ;
125+ $ b = \substr_count ($ this ->selector , '# ' );
126+ $ c = \preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->selector , $ aMatches );
127+ $ d = \preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->selector , $ aMatches );
128+ return ($ a * 1000 ) + ($ b * 100 ) + ($ c * 10 ) + $ d ;
141129 }
142130}
0 commit comments