From 05a1b594d8845a957a57e7d22a7c8337c87dd6b8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 27 Aug 2018 18:01:37 +0200 Subject: [PATCH] Sniff::is_safe_casted(): minor efficiency fixes --- WordPress/Sniff.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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'] ] ); } /**