@@ -128,7 +128,7 @@ protected function parseSelectorString($selector)
128128 }
129129
130130 // check for elements that do not have a specified attribute
131- if (isset ($ key [0 ]) AND $ key [0 ] == '! ' ) {
131+ if (isset ($ key [0 ]) && $ key [0 ] == '! ' ) {
132132 $ key = substr ($ key , 1 );
133133 $ noKey = true ;
134134 }
@@ -166,13 +166,15 @@ protected function parseSelectorString($selector)
166166 protected function seek (array $ nodes , array $ rule , array $ options )
167167 {
168168 // XPath index
169- if ( ! empty ($ rule ['tag ' ]) AND ! empty ($ rule ['key ' ]) AND
169+ if (count ($ rule ['tag ' ]) > 0 &&
170+ count ($ rule ['key ' ]) > 0 &&
170171 is_numeric ($ rule ['key ' ])
171172 ) {
172173 $ count = 0 ;
173174 /** @var AbstractNode $node */
174175 foreach ($ nodes as $ node ) {
175- if ($ rule ['tag ' ] == '* ' OR $ rule ['tag ' ] == $ node ->getTag ()->name ()) {
176+ if ($ rule ['tag ' ] == '* ' ||
177+ $ rule ['tag ' ] == $ node ->getTag ()->name ()) {
176178 ++$ count ;
177179 if ($ count == $ rule ['key ' ]) {
178180 // found the node we wanted
@@ -198,7 +200,7 @@ protected function seek(array $nodes, array $rule, array $options)
198200 $ child = $ node ->firstChild ();
199201 while ( ! is_null ($ child )) {
200202 // wild card, grab all
201- if ($ rule ['tag ' ] == '* ' AND is_null ($ rule ['key ' ])) {
203+ if ($ rule ['tag ' ] == '* ' && is_null ($ rule ['key ' ])) {
202204 $ return [] = $ child ;
203205 try {
204206 $ child = $ node ->nextChild ($ child ->id ());
@@ -211,21 +213,21 @@ protected function seek(array $nodes, array $rule, array $options)
211213
212214 $ pass = true ;
213215 // check tag
214- if ( ! empty ($ rule ['tag ' ]) AND $ rule ['tag ' ] != $ child ->getTag ()->name () AND
216+ if ( ! empty ($ rule ['tag ' ]) && $ rule ['tag ' ] != $ child ->getTag ()->name () &&
215217 $ rule ['tag ' ] != '* '
216218 ) {
217219 // child failed tag check
218220 $ pass = false ;
219221 }
220222
221223 // check key
222- if ($ pass AND ! is_null ($ rule ['key ' ])) {
224+ if ($ pass && ! is_null ($ rule ['key ' ])) {
223225 if ($ rule ['noKey ' ]) {
224226 if ( ! is_null ($ child ->getAttribute ($ rule ['key ' ]))) {
225227 $ pass = false ;
226228 }
227229 } else {
228- if ($ rule ['key ' ] != 'plaintext ' and
230+ if ($ rule ['key ' ] != 'plaintext ' &&
229231 is_null ($ child ->getAttribute ($ rule ['key ' ]))
230232 ) {
231233 $ pass = false ;
@@ -234,8 +236,8 @@ protected function seek(array $nodes, array $rule, array $options)
234236 }
235237
236238 // compare values
237- if ($ pass and ! is_null ($ rule ['key ' ]) and
238- ! is_null ($ rule ['value ' ]) and $ rule ['value ' ] != '* '
239+ if ($ pass && ! is_null ($ rule ['key ' ]) &&
240+ ! is_null ($ rule ['value ' ]) && $ rule ['value ' ] != '* '
239241 ) {
240242 if ($ rule ['key ' ] == 'plaintext ' ) {
241243 // plaintext search
@@ -248,7 +250,7 @@ protected function seek(array $nodes, array $rule, array $options)
248250 $ check = $ this ->match ($ rule ['operator ' ], $ rule ['value ' ], $ nodeValue );
249251
250252 // handle multiple classes
251- if ( ! $ check and $ rule ['key ' ] == 'class ' ) {
253+ if ( ! $ check && $ rule ['key ' ] == 'class ' ) {
252254 $ childClasses = explode (' ' , $ child ->getAttribute ('class ' ));
253255 foreach ($ childClasses as $ class ) {
254256 if ( ! empty ($ class )) {
0 commit comments