diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index e688876d45..1509de45b7 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -389,6 +389,19 @@ abstract class Sniff implements PHPCS_Sniff { 'sanitize_key' => true, ); + /** + * Token which when they preceed code indicate the value is safely casted. + * + * @since 1.1.0 + * + * @var array + */ + protected $safe_casts = array( + \T_INT_CAST => true, + \T_DOUBLE_CAST => true, + \T_BOOL_CAST => true, + ); + /** * Functions that format strings. * @@ -1560,8 +1573,12 @@ protected function is_safe_casted( $stackPtr ) { true ); + if ( false === $prev ) { + return false; + } + // Check if it is a safe cast. - return \in_array( $this->tokens[ $prev ]['code'], array( \T_INT_CAST, \T_DOUBLE_CAST, \T_BOOL_CAST ), true ); + return isset( $this->safe_casts[ $this->tokens[ $prev ]['code'] ] ); } /**