Loading coder_sniffer/DrupalPractice/Sniffs/General/ExceptionTSniff.php +11 −5 Original line number Diff line number Diff line Loading @@ -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() Loading coder_sniffer/DrupalPractice/Test/General/ExceptionTUnitTest.inc +8 −0 Original line number Diff line number Diff line Loading @@ -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'), ]), ]); } } Loading
coder_sniffer/DrupalPractice/Sniffs/General/ExceptionTSniff.php +11 −5 Original line number Diff line number Diff line Loading @@ -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() Loading
coder_sniffer/DrupalPractice/Test/General/ExceptionTUnitTest.inc +8 −0 Original line number Diff line number Diff line Loading @@ -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'), ]), ]); } }