Stars: 222
Forks: 26
Pull Requests: 138
Issues: 59
Watchers: 13
Last Updated: 2023-07-28 00:31:25
WordPress extensions for PHPStan ⛏️
License: MIT License
Languages: PHP, Shell
https://packagist.org/packages/szepeviktor/phpstan-wordpress
Static analysis for the WordPress ecosystem.
Add this package to your project.
composer require --dev szepeviktor/phpstan-wordpress
Make PHPStan find it automatically using phpstan/extension-installer
.
composer require --dev phpstan/extension-installer
Or manually include it in your phpstan.neon
.
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
Needs no extra configuration. 😃 Simply configure PHPStan - for example - this way.
parameters:
level: 5
paths:
- plugin.php
- inc/
Please read PHPStan Config Reference.
💡 Use Composer autoloader or a custom autoloader!
Please consider supporting my work.
Thank you!
Just start the analysis: vendor/bin/phpstan analyze
then fix an error and GOTO 10
!
You find further information in the examples
directory
e.g. examples/phpstan.neon.dist
Please see WooCommerce Stubs
php-stubs/wordpress-stubs
packageis_wp_error()
apply_filters()
and treats the type of its first @param
as certainapply_filters()
docblockWordPress core - and the wider WordPress ecosystem - uses PHPDoc docblocks
in a non-standard manner to document the parameters passed to apply_filters()
.
Example:
/**
* Filters the page title when creating an HTML drop-down list of pages.
*
* @param string $title Page title.
* @param WP_Post $page Page data object.
*/
$title = apply_filters( 'list_pages', $title, $page );
This extension understands these docblocks when they're present in your code
and uses them to instruct PHPStan to treat the return type of the filter as certain,
according to the first @param
tag. In the example above this means PHPStan treats the type of $title
as string
.
To make the best use of this feature,
ensure that the type of the first @param
tag in each of these such docblocks is accurate and correct.
class Name { ... }
inc/
apply_filters()
eval
, extract
, compact
, list
$a = '15'; if ($a) ...
if
needs a boolean),
see Variable handling functionsexit_error
in WP_CLI::launch
or WP_CLI::runcommand
to keep your code testableWordPress uses conditional function and class definition for override purposes.
Use sed
command to exclude function stubs when they are previously defined.
sed -i -e 's#function is_gd_image#function __is_gd_image#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php