larastan: Bug with autoloading on phpstan 0.12.22

  • Larastan Version: 0.5.7
  • PhpStan Version: 0.12.22
  • --level used: max

Description

For latest version of phpstan (0.12.22)!

On analyze action:

 ErrorException thrown in /builds/trv3/core/vendor/nunomaduro/larastan/src/ApplicationResolver.php on line 109 while loading bootstrap file /builds/trv3/core/vendor/phpstan/phpstan/../../nunomaduro/larastan/bootstrap.php: Undefined index: AI\Core\

Method ApplicationResolver@getProjectSearchDirs has wrong composer dir:

Expected: /home/vagrant/projects/core/vendor/composer Actual: phar:///home/vagrant/projects/ai/core/vendor/phpstan/phpstan/phpstan/vendor/composer

phpstan code reference: https://github.com/phpstan/phpstan-src/commit/a1d3990c95b7a064a0451111153a6bef39f5d9a2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 20 (4 by maintainers)

Commits related to this issue

Most upvoted comments

PHPStan 0.12.21 gives the same error for me, using 0.12.20 however works

Could you tell us about your project that uses Larastan but not Laravel?

Something along these lines will probably be sufficient: https://github.com/nunomaduro/larastan/pull/561

You don’t even need my suggestion with %composerAutoloaderProjectPaths% because I noticed that you’re getting composer.json from the current working directory anyway, so there’s no need for reflection to tell us the path to the Composer class loader…

I am a little bit tired today, maybe someone on the community would like to jump in: https://twitter.com/enunomaduro/status/1257400309212680197.

Can you explain what the code in /src/ApplicationResolver.php@master does and why are you inspecting the PSR4 maps?

I’m quite sure you could ask PHPStan for %composerAutoloaderProjectPaths% instead and discover autoloaders that way. It might return up to three autoloader paths I think.

In that class, we are trying to find all the service providers that the application uses. And register them to the Laravel app.

Looks like the issue is here: https://github.com/nunomaduro/larastan/blob/master/src/ApplicationResolver.php#L102-L104

When we request ClassLoader via reflection looks like it gets the vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php file. Not the vendor/composer/ClassLoader.php

Right now I don’t have the time to look deeper. Just a pointer if anyone wants to attempt a fix.