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 5132789
Show file tree
Hide file tree
Showing 3 changed files with 25 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace Consistence\Sniffs\Exceptions;

class ErrorArgumentChainableConstructorException extends \Exception
{

public function __construct(string $foo, \TypeError $e)
{
parent::__construct($foo, 0, $e);
}

}

0 comments on commit 5132789

Please sign in to comment.