Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DeadCatchSniff.php

function DeadCatchSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $catchPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Exceptions/DeadCatchSniff.php, line 31

Class

DeadCatchSniff

Namespace

SlevomatCodingStandard\Sniffs\Exceptions

Code

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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal