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

Breadcrumb

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

function ExceptionTSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the function: name in the stack.

Return value

void

Overrides Sniff::process

File

vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/ExceptionTSniff.php, line 48

Class

ExceptionTSniff
Checks that exceptions aren't translated.

Namespace

DrupalPractice\Sniffs\General

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $endPtr = $phpcsFile->findEndOfStatement($stackPtr);
    $newPtr = $phpcsFile->findNext(T_NEW, $stackPtr + 1, $endPtr);
    if ($newPtr !== false) {
        $openPtr = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $newPtr + 1, $endPtr);
        if ($openPtr !== false) {
            for ($i = $openPtr + 1; $i < $tokens[$openPtr]['parenthesis_closer']; $i++) {
                if ($tokens[$i]['code'] === T_STRING && $tokens[$i]['content'] === 't') {
                    $warning = 'Exceptions should not be translated';
                    $phpcsFile->addWarning($warning, $stackPtr, 'ExceptionT');
                    return;
                }
            }
        }
    }
}

API Navigation

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