Skip to content

Commit 3ccc769

Browse files
committed
Security/EscapeOutput: group common token check together
At various points within the `check_code_is_escaped()` loop, the sniff would check whether the current token is a token which can be ignored. This commit just groups those simple checks, which are not dependent on other logic in the loop, together and places them at the top of the loop for the highest efficiency.
1 parent 2f40190 commit 3ccc769

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

WordPress/Sniffs/Security/EscapeOutputSniff.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,12 @@ protected function check_code_is_escaped( $start, $end ) {
485485
continue;
486486
}
487487

488-
// Ignore namespace separators.
489-
if ( \T_NS_SEPARATOR === $this->tokens[ $i ]['code'] ) {
488+
// Skip over irrelevant tokens.
489+
if ( isset( Tokens::$magicConstants[ $this->tokens[ $i ]['code'] ] ) // Magic constants for debug functions.
490+
|| \T_NS_SEPARATOR === $this->tokens[ $i ]['code']
491+
|| \T_DOUBLE_ARROW === $this->tokens[ $i ]['code']
492+
|| \T_CLOSE_PARENTHESIS === $this->tokens[ $i ]['code']
493+
) {
490494
continue;
491495
}
492496

@@ -556,15 +560,6 @@ protected function check_code_is_escaped( $start, $end ) {
556560
continue;
557561
}
558562

559-
if ( \in_array( $this->tokens[ $i ]['code'], array( \T_DOUBLE_ARROW, \T_CLOSE_PARENTHESIS ), true ) ) {
560-
continue;
561-
}
562-
563-
// Handle magic constants for debug functions.
564-
if ( isset( Tokens::$magicConstants[ $this->tokens[ $i ]['code'] ] ) ) {
565-
continue;
566-
}
567-
568563
// Handle safe PHP native constants.
569564
if ( \T_STRING === $this->tokens[ $i ]['code']
570565
&& isset( $this->safe_php_constants[ $this->tokens[ $i ]['content'] ] )

0 commit comments

Comments
 (0)