diff --git a/Consistence/Sniffs/Exceptions/ExceptionDeclarationSniff.php b/Consistence/Sniffs/Exceptions/ExceptionDeclarationSniff.php index cf4cb86..5fc0645 100644 --- a/Consistence/Sniffs/Exceptions/ExceptionDeclarationSniff.php +++ b/Consistence/Sniffs/Exceptions/ExceptionDeclarationSniff.php @@ -116,6 +116,7 @@ private function checkThatExceptionIsChainable(PhpCsFile $phpcsFile, int $classP if ( $lastArgument->getTypeHint() !== '\Throwable' && !StringHelper::endsWith($lastArgument->getTypeHint(), 'Exception') + && !StringHelper::endsWith($lastArgument->getTypeHint(), 'Error') ) { $phpcsFile->addError(sprintf( 'Exception is not chainable. It must have optional \Throwable as last constructor argument and has "%s".', diff --git a/tests/Sniffs/Exceptions/ExceptionDeclarationSniffTest.php b/tests/Sniffs/Exceptions/ExceptionDeclarationSniffTest.php index 880ae16..07e892c 100644 --- a/tests/Sniffs/Exceptions/ExceptionDeclarationSniffTest.php +++ b/tests/Sniffs/Exceptions/ExceptionDeclarationSniffTest.php @@ -153,6 +153,15 @@ public function testExceptionWithCustomExceptionArgumentIsChainable() $this->assertNoSniffError($resultFile, 10); } + public function testExceptionWithErrorArgumentIsChainable() + { + $resultFile = $this->checkFile(__DIR__ . '/data/ErrorArgumentChainableConstructorException.php', [ + 'exceptionsDirectoryName' => 'data', + ]); + + $this->assertNoSniffError($resultFile, 10); + } + public function testExceptionWithNonchainableConstructorIsNotChainable() { $resultFile = $this->checkFile(__DIR__ . '/data/NonChainableConstructorException.php', [ diff --git a/tests/Sniffs/Exceptions/data/ErrorArgumentChainableConstructorException.php b/tests/Sniffs/Exceptions/data/ErrorArgumentChainableConstructorException.php new file mode 100644 index 0000000..55a14ea --- /dev/null +++ b/tests/Sniffs/Exceptions/data/ErrorArgumentChainableConstructorException.php @@ -0,0 +1,15 @@ +