Skip to content

Commit ed4ab50

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 3992a5f commit ed4ab50

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
@@ -624,14 +624,15 @@ public static function getSniffCode($sniffClass)
624624
throw new InvalidArgumentException('The $sniffClass parameter must be a non-empty string');
625625
}
626626

627-
$parts = explode('\\', $sniffClass);
628-
if (count($parts) < 4) {
627+
$parts = explode('\\', $sniffClass);
628+
$partsCount = count($parts);
629+
if ($partsCount < 4) {
629630
throw new InvalidArgumentException(
630631
'The $sniffClass parameter was not passed a fully qualified sniff(test) class name. Received: '.$sniffClass
631632
);
632633
}
633634

634-
$sniff = array_pop($parts);
635+
$sniff = $parts[($partsCount - 1)];
635636

636637
if (substr($sniff, -5) === 'Sniff') {
637638
// Sniff class name.
@@ -645,11 +646,9 @@ public static function getSniffCode($sniffClass)
645646
);
646647
}
647648

648-
$category = array_pop($parts);
649-
$sniffDir = array_pop($parts);
650-
$standard = array_pop($parts);
651-
$code = $standard.'.'.$category.'.'.$sniff;
652-
return $code;
649+
$standard = $parts[($partsCount - 4)];
650+
$category = $parts[($partsCount - 2)];
651+
return $standard.'.'.$category.'.'.$sniff;
653652

654653
}//end getSniffCode()
655654

0 commit comments

Comments
 (0)