Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Analyzing services with 'get' methods breaks following files #96

Open
@nreynis

Description

Bug report

Analyzing nested services which have get methods produces weird side effect on other files.
It seems to break something container/autoloader related.
It then causes classes to not be loaded properly and not be processed by dg/bypass-finals.
And breaks (in this example) intersection types.

Having one service with a get method doesn't seems to be enough, I can only reproduce it with two.
This is really hard to pinpoint because it is order dependent, so it may work on some machines because the analysis order is not deterministic. Also parallel processing makes that even more flaky.

The bug may seems to be really obscure edge case, but it's really not that hard to stumble on it: if you have a service/repository architecture (which symfony project usually have) you really likely to have nested get calls.

Minimal reproducible setup

https://github.com/yannickroger/phpstan-troubleshoot

In the neon file if you swap the order of the two analyzed files you can trigger the error on and off.

Actual result

Depending on the analysis order you may have this error:

------ -------------------------------------------------------------
 Line test/MyClassTest.php
------ -------------------------------------------------------------
 10 PHPDoc tag @var for property MyClassTest::$myClass contains
 unresolvable type.
------ -------------------------------------------------------------

Expected result

Type should be resolved and the analysis shouldn't yield any error, whatever the analysis order is.

Related to

phpstan/phpstan#3179

Likely culprit

Considering it's really dependant on the get method name (renaming methods fix the bug) it is very likely related to this part of the code:
https://github.com/phpstan/phpstan-symfony/blob/master/src/Type/Symfony/ServiceDynamicReturnTypeExtension.php#L41

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

        AltStyle によって変換されたページ (->オリジナル) /