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

Breadcrumb

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

class CatchHelper

@internal

Hierarchy

  • class \SlevomatCodingStandard\Helpers\CatchHelper

Expanded class hierarchy of CatchHelper

3 files declare their use of CatchHelper
DeadCatchSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Exceptions/DeadCatchSniff.php
ReferenceThrowableOnlySniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Exceptions/ReferenceThrowableOnlySniff.php
RequireNonCapturingCatchSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Exceptions/RequireNonCapturingCatchSniff.php

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/CatchHelper.php, line 15

Namespace

SlevomatCodingStandard\Helpers
View source
class CatchHelper {
    public static function getTryEndPointer(File $phpcsFile, int $catchPointer) : int {
        $tokens = $phpcsFile->getTokens();
        $endPointer = $tokens[$catchPointer]['scope_closer'];
        do {
            $nextPointer = TokenHelper::findNextEffective($phpcsFile, $endPointer + 1);
            if ($nextPointer === null || !in_array($tokens[$nextPointer]['code'], [
                T_CATCH,
                T_FINALLY,
            ], true)) {
                break;
            }
            $endPointer = $tokens[$nextPointer]['scope_closer'];
        } while (true);
        return $endPointer;
    }
    
    /**
     * @param array<string, array<int, int|string>|int|string> $catchToken
     * @return list<string>
     */
    public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken) : array {
        
        /** @var int $catchParenthesisOpenerPointer */
        $catchParenthesisOpenerPointer = $catchToken['parenthesis_opener'];
        
        /** @var int $catchParenthesisCloserPointer */
        $catchParenthesisCloserPointer = $catchToken['parenthesis_closer'];
        $nameTokenCodes = TokenHelper::getNameTokenCodes();
        $nameEndPointer = $catchParenthesisOpenerPointer;
        $tokens = $phpcsFile->getTokens();
        $caughtTypes = [];
        do {
            $nameStartPointer = TokenHelper::findNext($phpcsFile, array_merge([
                T_BITWISE_OR,
            ], $nameTokenCodes), $nameEndPointer + 1, $catchParenthesisCloserPointer);
            if ($nameStartPointer === null) {
                break;
            }
            if ($tokens[$nameStartPointer]['code'] === T_BITWISE_OR) {
                
                /** @var int $nameStartPointer */
                $nameStartPointer = TokenHelper::findNextEffective($phpcsFile, $nameStartPointer + 1, $catchParenthesisCloserPointer);
            }
            $pointerAfterNameEndPointer = TokenHelper::findNextExcluding($phpcsFile, $nameTokenCodes, $nameStartPointer + 1);
            $nameEndPointer = $pointerAfterNameEndPointer === null ? $nameStartPointer : $pointerAfterNameEndPointer - 1;
            $caughtTypes[] = NamespaceHelper::resolveClassName($phpcsFile, TokenHelper::getContent($phpcsFile, $nameStartPointer, $nameEndPointer), $catchParenthesisOpenerPointer);
        } while (true);
        return $caughtTypes;
    }

}

Members

Title Sort descending Modifiers Object type Summary
CatchHelper::findCaughtTypesInCatch public static function *
CatchHelper::getTryEndPointer public static function

API Navigation

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