PHPStan: Difference between revisions
No edit summary |
change category to Static Analysis |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
https://phpstan.org/ | https://phpstan.org/ has a quarter of a million installs as of early 2024 (just from packagist). Written largely by Ondřej Mirtes. | ||
PHPStan seems more polished (perhaps because it's commercial and has a 'pro' version that adds a GUI) whereas [[phan]] is the original PHP static analysis tool Rasmus Ledorf uses. | PHPStan seems more polished (perhaps because it's commercial and has a 'pro' version that adds a GUI) whereas [[phan]] is the original PHP static analysis tool Rasmus Ledorf uses. | ||
| Line 5: | Line 5: | ||
PHPStan has some very notable projects that integrate it: Symphony, Doctrine, Monolog, and many more. (A common refrain: there are PHPStan integrations for Drupal and Wordpress, but not MediaWiki.) | PHPStan has some very notable projects that integrate it: Symphony, Doctrine, Monolog, and many more. (A common refrain: there are PHPStan integrations for Drupal and Wordpress, but not MediaWiki.) | ||
Adding a configuration file for your MediaWiki extension is straightforward and would look like this:<syntaxhighlight lang="yaml"> | Adding a configuration file for your MediaWiki extension is straightforward and would look like this: | ||
<syntaxhighlight lang="yaml"> | |||
parameters: | parameters: | ||
level: 1 | level: 1 | ||
| Line 29: | Line 31: | ||
==Analyzing in depth== | ==Analyzing in depth== | ||
For an example of best-practices, single extension usage, see [https://github.com/ProfessionalWiki/Maps/blob/ee88211fadb3573b646cce005383450e96c3054e/phpstan.neon the example of Professional Wiki's Maps extension] which illustrates configuration file includes of a 'baseline'; error message suppression; and directory exclusions of problem code. | For an example of best-practices, single extension usage, see [https://github.com/ProfessionalWiki/Maps/blob/ee88211fadb3573b646cce005383450e96c3054e/phpstan.neon the example of Professional Wiki's Maps extension] which illustrates configuration file includes of a 'baseline'; error message suppression; and directory exclusions of problem code. | ||
==Adding Extensions to PHPStan== | |||
The PHPStan project has built a [[Composer]] plugin for the automatic installation of PHPStan extensions, [https://github.com/phpstan/extension-installer phpstan/extension-installer]. | |||
All you have to do is <code>composer require --dev phpstan/extension-installer</code> in your project and then you can e.g. <code>composer require --dev phpstan/phpstan-phpunit</code> to also add the [https://github.com/phpstan/phpstan-phpunit PHPUnit extension to PHPStan] rather than having to manually edit the <code>include</code> section of your phpstan.neon configuration. | |||
There are extensions for Doctrine, PHPUnit, Symfony Framework, Mockery, Nette Framework, Laravel, Drupal, WordPress etc. See [https://phpstan.org/user-guide/extension-library the extension library] | |||
[[Category:Wiki]] | [[Category:Wiki]] | ||
| Line 35: | Line 44: | ||
[[Category:QA]] | [[Category:QA]] | ||
[[Category:Testing]] | [[Category:Testing]] | ||
[[Category:Analysis]] | [[Category:Static Analysis]] | ||
[[Category:Tools]] | [[Category:Tools]] | ||
[[Category:Continuous Integration]] | [[Category:Continuous Integration]] | ||