From 659becb59ff029d60ff0d0af126ebfc51e5afa5f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 5 Jun 2024 18:37:58 +0200 Subject: [PATCH] Common::getSniffCode(): minor simplification * Remove the use of `array_pop()` in favour of directly referencing the required "parts" by their index in the array. * Remove the unused `$sniffDir` variable. * Remove the unnecessary `$code` variable. Related to [review comment in PR 446](https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/446#discussion_r1573947430). --- src/Util/Common.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Util/Common.php b/src/Util/Common.php index 2428f78d7d..af4aba69fd 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -540,14 +540,15 @@ public static function getSniffCode($sniffClass) throw new InvalidArgumentException('The $sniffClass parameter must be a non-empty string'); } - $parts = explode('\\', $sniffClass); - if (count($parts) < 4) { + $parts = explode('\\', $sniffClass); + $partsCount = count($parts); + if ($partsCount < 4) { throw new InvalidArgumentException( 'The $sniffClass parameter was not passed a fully qualified sniff(test) class name. Received: '.$sniffClass ); } - $sniff = array_pop($parts); + $sniff = $parts[($partsCount - 1)]; if (substr($sniff, -5) === 'Sniff') { // Sniff class name. @@ -561,11 +562,9 @@ public static function getSniffCode($sniffClass) ); } - $category = array_pop($parts); - $sniffDir = array_pop($parts); - $standard = array_pop($parts); - $code = $standard.'.'.$category.'.'.$sniff; - return $code; + $standard = $parts[($partsCount - 4)]; + $category = $parts[($partsCount - 2)]; + return $standard.'.'.$category.'.'.$sniff; }//end getSniffCode()