class DeadCatchSniff
Hierarchy
- class \SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of DeadCatchSniff
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Exceptions/ DeadCatchSniff.php, line 12
Namespace
SlevomatCodingStandard\Sniffs\ExceptionsView source
class DeadCatchSniff implements Sniff {
public const CODE_CATCH_AFTER_THROWABLE_CATCH = 'CatchAfterThrowableCatch';
/**
* @return array<int, (int|string)>
*/
public function register() : array {
return [
T_CATCH,
];
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param int $catchPointer
*/
public function process(File $phpcsFile, $catchPointer) : void {
$tokens = $phpcsFile->getTokens();
$catchToken = $tokens[$catchPointer];
$caughtTypes = CatchHelper::findCaughtTypesInCatch($phpcsFile, $catchToken);
if (!in_array('\\Throwable', $caughtTypes, true)) {
return;
}
$nextCatchPointer = TokenHelper::findNextEffective($phpcsFile, $catchToken['scope_closer'] + 1);
while ($nextCatchPointer !== null) {
$nextCatchToken = $tokens[$nextCatchPointer];
if ($nextCatchToken['code'] !== T_CATCH) {
break;
}
$phpcsFile->addError('Unreachable catch block.', $nextCatchPointer, self::CODE_CATCH_AFTER_THROWABLE_CATCH);
$nextCatchPointer = TokenHelper::findNextEffective($phpcsFile, $nextCatchToken['scope_closer'] + 1);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DeadCatchSniff::CODE_CATCH_AFTER_THROWABLE_CATCH | public | constant | ||
DeadCatchSniff::process | public | function | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * |
Overrides Sniff::process |
DeadCatchSniff::register | public | function | * | Overrides Sniff::register |