Skip to content

Commit 7449b29

Browse files
committed
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](#446 (comment)).
1 parent 2aac9ad commit 7449b29

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Util/Common.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,15 @@ public static function getSniffCode($sniffClass)
540540
throw new InvalidArgumentException('The $sniffClass parameter must be a non-empty string');
541541
}
542542

543-
$parts = explode('\\', $sniffClass);
544-
if (count($parts) < 4) {
543+
$parts = explode('\\', $sniffClass);
544+
$partsCount = count($parts);
545+
if ($partsCount < 4) {
545546
throw new InvalidArgumentException(
546547
'The $sniffClass parameter was not passed a fully qualified sniff(test) class name. Received: '.$sniffClass
547548
);
548549
}
549550

550-
$sniff = array_pop($parts);
551+
$sniff = $parts[($partsCount - 1)];
551552

552553
if (substr($sniff, -5) === 'Sniff') {
553554
// Sniff class name.
@@ -561,11 +562,9 @@ public static function getSniffCode($sniffClass)
561562
);
562563
}
563564

564-
$category = array_pop($parts);
565-
$sniffDir = array_pop($parts);
566-
$standard = array_pop($parts);
567-
$code = $standard.'.'.$category.'.'.$sniff;
568-
return $code;
565+
$standard = $parts[($partsCount - 4)];
566+
$category = $parts[($partsCount - 2)];
567+
return $standard.'.'.$category.'.'.$sniff;
569568

570569
}//end getSniffCode()
571570

0 commit comments

Comments
 (0)