szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
262 stars 26 forks source link

Incompatible with WP-CLI 2.8.0 #188

Closed johnbillion closed 1 year ago

johnbillion commented 1 year ago

WP-CLI 2.8.0 was released yesterday. One of the larger changes was to upgrade to Requests v2, which means its autoloader now looks for and loads classes in the \WpOrg\Requests namespace.

The szepeviktor/phpstan-wordpress package depends on the php-stubs/wordpress-stubs package and loads it when running PHPStan. The php-stubs/wordpress-stubs package includes the \WpOrg\Requests classes in its stubs.

Running the PHPStan analysis on a project that depends on both szepeviktor/phpstan-wordpress and wp-cli/wp-cliresults in a redeclaration error. I've not dug into the details but it appears the stubs definitions load first, then something inside Requests still causes it to attempt to redeclare \WpOrg\Requests\Autoload. I will try to find some time to look into why that's happening.

phpstan analyze --memory-limit=1024M
Note: Using configuration file phpstan.neon.dist.
Fatal error: Cannot declare class WpOrg\Requests\Autoload, because the name is already in use in vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18381
chesio commented 1 year ago

Perhaps related: https://github.com/wp-cli/wp-cli/issues/5795

johnbillion commented 1 year ago

Some more information: The project does not depend directly on wp-cli/wp-cli, it depends on lucatume/wp-browser for automated testing, and that package depends on wp-cli/wp-cli.

szepeviktor commented 1 year ago

Please use php-stubs/wp-cli-stubs for static analysis.

justlevine commented 1 year ago

@chesio not "perhaps related", but what prompted me to open that issue in the first place 😇

Temporary workaround is to set wp-cli/wp-cli to ~2.7.x locally, to stop other deps from leaking the higher version.

szepeviktor commented 1 year ago

What a flash mob!!

johnbillion commented 1 year ago

Reading through the issue above, I think this is a problem in WP-CLI. It's trying to redeclare a \WpOrg\Requests class after it's already defined by WordPress core (or in this case, by the stubs).

johnbillion commented 1 year ago

This has been fixed in WP-CLI 2.8.1