Unverified Commit d1879816 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(ExceptionT): Only check for translation within the exception (#3123061 by Arkener)

parent abe72b86
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -51,13 +51,19 @@ class ExceptionTSniff implements Sniff
        $tokens = $phpcsFile->getTokens();
        $endPtr = $phpcsFile->findEndOfStatement($stackPtr);

        for ($i = ($stackPtr + 1); $i < $endPtr; $i++) {
        $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;
                    }
                }
            }
        }

    }//end process()

+8 −0
Original line number Diff line number Diff line
@@ -18,4 +18,12 @@ class ExceptionExample {
    return $this->t('Error');
  }

  public function dolor() {
    throw (new PipelineStepExecutionLogicException('Graph data could not be inserted'))->setUserMessage([
      '#markup' => $this->t('Could not store triples in triple store. Reason: @message', [
        '@message' => t('Failed'),
      ]),
    ]);
  }

}