coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Problem with Consistence.Exceptions.ExceptionDeclaration

Open lookyman opened this issue 7 years ago • 3 comments

use Throwable;

class InvalidResponseException extends Exception
{
    public function __construct(Validator $validator, ?Throwable $previous = null)
    {
        // ...
    }

This reports Exception is not chainable. It must have optional \Throwable as last constructor argument and has "Throwable".

lookyman avatar Jul 30 '18 13:07 lookyman

Is this the whole class? As in there is no namespace? (I see no PHP open tag and Exception is not used while Throwable is, so it seems pretty suspicious to me).

VasekPurchart avatar Jul 31 '18 09:07 VasekPurchart

Nope, of course it's not a whole class 😊 It's just an excerpt to show the issue. The problem seems to be here.

lookyman avatar Jul 31 '18 09:07 lookyman

This problem is not fixed in https://github.com/consistence-community/coding-standard/pull/3/files - condition accepts only FCQN.

Use

if (
    !in_array($lastArgument->getTypeHint(), ['\Throwable', '?\Throwable', 'Throwable', '?Throwable'], true)
    && !StringHelper::endsWith($lastArgument->getTypeHint(), 'Exception')
    && !StringHelper::endsWith($lastArgument->getTypeHint(), 'Error')
)

instead of line 119 where was added: $lastArgument->getTypeHint() !== '?\Throwable'

miroslavhajek avatar Dec 29 '21 10:12 miroslavhajek