Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benefit from static analysis #38

Open
szepeviktor opened this issue Dec 17, 2019 · 2 comments
Open

Benefit from static analysis #38

szepeviktor opened this issue Dec 17, 2019 · 2 comments

Comments

@szepeviktor
Copy link
Contributor

szepeviktor commented Dec 17, 2019

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
Copy link
Contributor Author

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.

@szepeviktor szepeviktor changed the title Benefir from static analysis Benefit from static analysis Dec 17, 2019
@imath
Copy link
Owner

imath commented Dec 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants