phpstan/phpstan-shim

bootstrap.php prevents autoloading of certain files from shared dependencies with project

fmasa opened this issue · 4 comments

fmasa commented

Even though this package should make it easier to use side-by-side with application dependencies, there is problem with way Composer autoincludes files autoloaded via autoload.files.

The file, that makes problems, is vendor/nette/di/compatibility.php.

What happens

When Composer includes bootstrap.php, it includes files from all dependencies, that are mentioned in autoload with type files. Composer then saves file identifiers of those files to $GLOBALS ($GLOBALS['__composer_autoload_files'][$fileIdentifier] = true) "Same" files used by project are then skipped. Note that this is may or may not work depending on order of packages calculated by Composer.

Cause

This is regression caused by e7dd0a0.

phpstan/phpstan-shim autoloader probably should not pollute application autoloading if it's not running in context of phpstan analysis.

Hi, I plan to make some changes in this area, I need to have package with PHPStan as PHAR be usable by everyone.

fmasa commented

Is there a way for me to help? 🙂

There is dirty way to work around this issue in my project (defining __PHPSTAN_RUNNING__ constant in some custom bootstrap file, that is not analyzed), but it can be rather confusing for other users.

You can try :) My plan is to have a custom autoloader inside bootstrap.php that only loads PHPStan and PhpParser classes from inside the PHAR when they are requested.

Please try current dev-master. 10caff5