Skip to content

"Call to static method Food::bar() on a separate line has no effect" inside try/catch #10819

@chriscollinsboxuk

Description

@chriscollinsboxuk

Bug report

The following code generates an error when I don't believe it should:

try {
    RamseyUuid::fromString($id);
} catch (InvalidArgumentException) {
    throw new InvalidArgumentException('Invalid UUID string provided: ' . $id . '.');
}

Assigning RamseyUuid::fromString($id) to a temporary variable suppresses the issue, but other things (such as SonarCloud) complain about this unused temporary variable.

This seems almost identical to #9564 which was apparently fixed, but this is for a static method.

Code snippet that reproduces the problem

I created a similar example using the DateTime class here: https://phpstan.org/r/07c8eb92-0f17-4b83-9504-657ec679da3a

Expected output

No error reported.

Did PHPStan help you today? Did it make you happy in any way?

We all love PHPStan and use it every day at Box UK :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions