Skip to content

Class property defined in a trait generates false positives. #1835

@polishExperiment

Description

@polishExperiment

I use PHPStan version dev-master@07601ea.

I have a ListModuleVersionsController class that uses a trait IsListControllerTrait. That trait has private property $repository therefore I don't need to define $repository in ListModuleVersionsController.

I inject AbstractModuleRepository in constructor of ListModuleVersionsControler and assign it to $repository property. Since $repository property is defined in a trait as having the type of PaginableRepositoryInterface, PHPStan interprets type of $repository property in context of ListModuleVersionsController as being of type PaginableRepositoryInterface. It produces false positive errors e.g. methods missing due to wrong type detection of $repository property in ListModuleVersionsController.

Wouldn't it be great if PHPStan was able to correctly determine the type of class' property when it's defined only in a trait and re-assigned in class' constructor?

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