Skip to content

Commit

Permalink
Error last argument is considered chainable
Browse files Browse the repository at this point in the history
  • Loading branch information
VasekPurchart committed Sep 22, 2017
1 parent 5b2879d commit 9bc8789
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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".',
Expand Down
9 changes: 9 additions & 0 deletions tests/Sniffs/Exceptions/ExceptionDeclarationSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down

0 comments on commit 9bc8789

Please sign in to comment.