bitExpert / phpstan-magento

Magento specific extension for PHPStan
MIT License
134 stars 24 forks source link

Upgrade to PHPStan 1.7 #243

Closed shochdoerfer closed 2 years ago

shochdoerfer commented 2 years ago

The upgrade is currently blocked by an issue with bitExpert\PHPStan\Magento\Autoload\Cache\FileCacheStorage where mkdir() seems to fail to create the needed directory structure.

shochdoerfer commented 2 years ago

Maybe it will be possible to migrate the whole autoloader magic to PHPStan's BetterReflection\SourceLocator implementation.

shochdoerfer commented 2 years ago

For reference, this is the issue I opened in the phpstan repo: https://github.com/phpstan/phpstan/issues/7293

shochdoerfer commented 2 years ago

Current plan: Refactor the autoloaders. Get rid of the cache and remove the laminas-code dependency in the extension attribute & extension interface autoloaders as those also seem to cause issues with the BetterReflection reflection logic used by PHPStan 1.7.

It seems important to make the autoloader implementations as dump as possible and as independent as possible. All dependencies need to be injected and not instantiated manually as this causes a problem with laminas-code.

shochdoerfer commented 2 years ago

This is a lot more complicated than expected. After removing the cache and the laminas-code dependency, I got stuck with a problem in the ExtensionAttributeDataProvider. The BetterReflection autoloader magic in PHPStan does not allow the instantiation of new objects (I assume unknown classes - as in not already loaded classes).

Hitting a dead-end road with this. Need to look for alternatives how to hook into PHPStan.

shochdoerfer commented 2 years ago

Eval()ing code in the autoloaders also does not work, an error I get now is Interface "Magento\Framework\Api\ExtensionAttributesInterface" not found in file. I don't see a way to dynamically load classes that don't exist anymore.

shochdoerfer commented 2 years ago

Problem fixed in PHPStan core 1.7.2.