Skip to content

Problem with Consistence.Exceptions.ExceptionDeclaration #47

Open

Description

@lookyman
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".

Activity

  1. VasekPurchart commented on Jul 31, 2018

    @VasekPurchart
    Member

    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).

  2. lookyman commented on Jul 31, 2018

    @lookyman
    Author

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

  3. miroslavhajek commented on Dec 29, 2021

    @miroslavhajek

    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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions