bitExpert / phpstan-magento

Magento specific extension for PHPStan
MIT License
133 stars 25 forks source link

Add support for PHP 8.2 #282

Closed hostep closed 1 year ago

hostep commented 1 year ago

Hi there!

Currently this package can't be installed using PHP 8.2 because of the constraint "laminas/laminas-code": "~3.3.0 || ~3.4.1 || ~3.5.1 || ~4.5.0 || ~4.5.2"

Would it be possible to start testing with laminas/laminas-code version 4.8.0? It got support for PHP 8.2 via https://github.com/laminas/laminas-code/commit/a6b26d6056d8732149efbcd5ba49f8776eee26da

Also, the version constraint in Magento 2.4.6-beta1 is set like this: "laminas/laminas-code": "^4.5" (and in Magento 2.4.5-p1 it was set like "laminas/laminas-code": "~4.5.0"), maybe this can be taken over?

After some quick testing myself, with version 4.8.0, I see that phpstan checks still work perfectly fine.

What will need some fixing in this package, is the deprecated usage of a certain syntax in PHP 8.2, this is what I noticed in the output during executing of phpstan on my little module but maybe there are more issues in other code in this package:

PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/DataProvider/ExtensionAttributeDataProvider.php on line 53
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/DataProvider/ExtensionAttributeDataProvider.php on line 53
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php on line 93
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php on line 93

Thanks!

shochdoerfer commented 1 year ago

Thanks for opening the issue. The "incompatibility" is coming from Magento 2.4.6-beta1 and trying to use our extension, right?

So far my goal was to use the exact same version constraints as Magento core to "minimize" the risk of dependency problems. If the latest version broadens the version scope of the laminas/laminas-code, I guess it is fine to switch the constraint to ^4.5. So far, I was not running into issues with laminas/laminas-code in the different versions, their public API seems to be stable. It is "just" the internal functionality that was changed to adapt to the different PHP versions.

I wasn't aware that ${var} is not a valid syntax anymore. Since laminas/laminas-code got introduced by the PR regarding the extension attributes, I had in mind to change the code generation in all other autoloaders also but I just did not find the time yet to do that. Any chance you could help out? Would be nice to have the extension compatible with 2.4.6 once it gets released.

hostep commented 1 year ago

Sure, I'll try to send in a PR in of the coming days 🙂

Yesterday evening I also quickly tested with the develop branch of https://github.com/PHPCompatibility/PHPCompatibility the code of this package, to check for other incompatibilities with PHP 8.2 and it was only those two syntax things it found. So I think it's going to be easy to introduce support for PHP 8.2 (and Magento 2.4.6).

shochdoerfer commented 1 year ago

Very much appreciated! If you need help or you have questions, let me know.