vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.57k stars 660 forks source link

"Could not get class storage for X" #10895

Open akaDJon opened 7 months ago

akaDJon commented 7 months ago

I got error "Could not get class storage for X" with my codebase. I see many issues on github with this problem. My codebase has many aliases and I found solve!

I fix it in file AssertionsFromInheritanceResolver.php. I added function getUnAliasedName:

before:

        foreach ($inherited_classes_and_interfaces as $potential_assertion_providing_class) {
            $potential_assertion_providing_classlike_storage = $this->codebase->classlike_storage_provider->get(
                $potential_assertion_providing_class,
            );

after:

        foreach ($inherited_classes_and_interfaces as $potential_assertion_providing_class) {
            $potential_assertion_providing_class = $this->codebase->classlikes->getUnAliasedName($potential_assertion_providing_class);

            $potential_assertion_providing_classlike_storage = $this->codebase->classlike_storage_provider->get(
                $potential_assertion_providing_class,
            );
veewee commented 4 months ago

Hello,

I am facing a similar issue in sulu, which I described and reported here: https://github.com/sulu/sulu/issues/7523

The fix provided above solves the issue for this specific case as well. I tried creating a simple reproducer, but cannot figure out in what specific case psalm isn't able to track it anymore.

Would you be interested in a PR (without additional tests)? If not : Maybe someone with broader understanding of psalm internals could take a look at what could possibly go wrong here?

blm768 commented 1 month ago

Could this be related to #4462?