Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error last argument is considered chainable #28

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}