magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

Add PHPStan to Magento static checks #211

Closed larsroettig closed 4 years ago

larsroettig commented 5 years ago

Summary (*)

As the architecture team discussed at https://github.com/magento/architecture/pull/114 we should add PHPStan as developer composer dependencies.

How: composer require --dev phpstan/phpstan Add check to dev/tests/static/phpunit.xml.dist

Expected behaviour (*)

PHPStan run with the Magento static checks

Actual result (*)

Php Stan is not installed and does not run with the static checks

Examples (*)

Benefits

Following types of issues can be found in Magento codebase: the use of undefined class; call to undefined function; missing parent::__construct() call; passed arguments mismatch, etc.

Additional information

The Drupal people also picked up phpstan, read some insights https://glamanate.com/blog/writing-better-drupal-code-static-analysis-using-phpstan

Proposed solution

magento-engcom-team commented 5 years ago

Hi @larsroettig. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@larsroettig do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

lenaorobei commented 5 years ago

Additional details:

ondrejmirtes commented 5 years ago

Looking forward to closely observe this :) The main challenge when getting level 0 to run is to configure autoloading properly - sometimes projects rely on weird autoloading rules or custom autoloader. Most commonly, there's problem with PHPUnit testcases - they have to be present at least in autoload-dev too.

This is important to get right:

* Have class definitions in files by themselves, not mix them with any side-effects (like code below the class definition that runs when the class is autoloaded)

shochdoerfer commented 5 years ago

You might want to follow our work regarding Magento support for PHPStan here until there's an official extension ;)

lenaorobei commented 4 years ago

PHPStan was added to Magento https://github.com/magento/magento2/blob/2.4-develop/composer.json#L95