From bfafc5837d16d72462ea1e63e59172f9e1d1c371 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 26 Apr 2021 11:00:38 +0200 Subject: [PATCH] Handle exception without parenthesis --- SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php | 6 +++++- SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.inc | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php b/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php index 3d92619..aa58ad0 100644 --- a/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php +++ b/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php @@ -29,7 +29,11 @@ public function register(): array public function process(File $phpcsFile, $stackPtr): void { $tokens = $phpcsFile->getTokens(); - $opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); + $opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true); + if (false === $opener) { + return; + } + $concat = $phpcsFile->findNext( T_STRING_CONCAT, $tokens[$opener]['parenthesis_opener'], diff --git a/SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.inc b/SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.inc index 5524124..158376c 100644 --- a/SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.inc +++ b/SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.inc @@ -16,4 +16,9 @@ class Errors throw new \RuntimeException('Unrecognized option '.$option); } + + public function testLast(\Exception $exception) + { + throw $exception; + } }