imath / wp-statuses

WordPress plugin to ease Custom Post Statuses integration
GNU General Public License v2.0
160 stars 27 forks source link

Benefit from static analysis #38

Open szepeviktor opened 4 years ago

szepeviktor commented 4 years ago

Please try running @phpstan on raising levels.

phpstan.neon.dist

#$ composer require --dev szepeviktor/phpstan-wordpress
#$ vendor/bin/phpstan analyze -l 0

includes:
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
    level: max
    inferPrivatePropertyTypeFromConstructor: true
    paths:
        - wp-statuses.php
        - inc/
    autoload_files:
        - wp-statuses.php
        - inc/core/functions.php
        - inc/core/custom.php
        - inc/core/classes/class-wp-statuses-core-status.php
        - inc/admin/classes/class-wp-statuses-admin.php
    dynamicConstantNames:
        - EMPTY_TRASH_DAYS
    ignoreErrors:
        # Uses func_get_args()
        - '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
        # TODO Define properties!
        - '#^Access to an undefined property WP_Statuses::\$[a-z_]+\.$#'
        # TODO Specify type hints!
        - '# has no return typehint specified\.$#'
        # It is a PHPStan bug.
        - '#^Parameter \#1 \$autoload_function of function spl_autoload_register expects callable\(string\): #'
    # TODO Remove!
    checkMissingIterableValueType: false
szepeviktor commented 4 years ago

e.g. defined( 'ABSPATH' ) || exit; properly and testable looks like

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

PHPStan is able to detect problems hidden for the human eye.

imath commented 4 years ago

Interesting, I was thinking about using PHPCS along with WP code formatting config. Thanks for you feedback.