Skip to content

Commit

Permalink
Common::getSniffCode(): minor simplification
Browse files Browse the repository at this point in the history
* 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)).
  • Loading branch information
jrfnl committed Sep 29, 2024
1 parent 2aac9ad commit 7449b29
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Util/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()

Expand Down

0 comments on commit 7449b29

Please sign in to comment.