Skip to content

InvalidNoReturn complains when all function does is throw #2099

@iluuu1994

Description

@iluuu1994

Imagine the following:

interface IFoo
{
    /**
     * @return string[]
     */
    public function foo(): array;
}

class Foo implements IFoo
{
    /**
     * @return string[]
     */
    public function foo(): array
    {
        throw new \Exception('This should never happen');
    }
}

This gives me the following error message:

Function has no return statement, but annotation @return is present (Squiz.Commenting.FunctionComment.InvalidNoReturn)

There's two possible solutions:

  • Drop the @return tag
  • Add a dummy-return after the throw \Exception
    • This is obviously also not great as you'll get a "unreachable statement" warning

This is probably very very hard to track without an AST...

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