-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix problems reported by static analysis #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @szepeviktor, thanks for the PR!
Can you please share the config and analysis result running PHPStan? Running PHPStan locally with rule level set to 6
and I got a different report:
My environment
% php -v
PHP 8.0.0 (cli) (built: Dec 17 2020 18:30:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
with Xdebug v3.0.0, Copyright (c) 2002-2020, by Derick Rethans
% composer show
10up/phpcs-composer dev-master 2f5c360
dealerdirect/phpcodesniffer-composer-installer dev-master 7d5cb88 PHP_CodeSniffer Standards Composer Installer Plugin
phpcompatibility/php-compatibility 9.3.5 A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.
phpcompatibility/phpcompatibility-paragonie 1.3.1 A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accou...
phpcompatibility/phpcompatibility-wp 2.1.2 A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting fo...
phpstan/phpstan 1.7.x-dev fc12215 PHPStan - PHP Static Analysis Tool
squizlabs/php_codesniffer dev-master f268ca4 PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
wp-coding-standards/wpcs 2.3.0 PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions
Config file
parameters:
level: 6
paths:
- ./simple-page-ordering.php
scanDirectories:
- /Users/tenup/Sites/oss/app/public/wp-includes/
Report
130 % ./vendor/bin/phpstan analyse -c phpstan.neon
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ -----------------------------------------------------------------------------------------------------------------------------
Line simple-page-ordering.php
------ -----------------------------------------------------------------------------------------------------------------------------
32 Class Simple_Page_Ordering referenced with incorrect case: Simple_page_Ordering.
54 Method Simple_Page_Ordering::add_actions() has no return type specified.
64 Method Simple_Page_Ordering::load_textdomain() has no return type specified.
71 Method Simple_Page_Ordering::load_edit_screen() has no return type specified.
72 Function get_current_screen not found.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
102 Method Simple_Page_Ordering::wp() has no return type specified.
104 Function get_current_screen not found.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
124 Method Simple_Page_Ordering::admin_head() has no return type specified.
125 Function get_current_screen not found.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
191 Method Simple_Page_Ordering::page_ordering() has invalid return type obj.
191 Method Simple_Page_Ordering::page_ordering() has parameter $excluded with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
369 Method Simple_Page_Ordering::page_ordering() should return obj|WP_Error but returns string.
375 Method Simple_Page_Ordering::page_ordering() should return obj|WP_Error but returns stdClass.
385 Method Simple_Page_Ordering::sort_by_order_link() has parameter $views with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
385 Method Simple_Page_Ordering::sort_by_order_link() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
414 Method Simple_Page_Ordering::rest_api_init() has no return type specified.
460 Method Simple_Page_Ordering::rest_page_ordering() has no return type specified.
468 Result of && is always false.
468 Variable $nextid in isset() always exists and is not nullable.
468 Variable $previd in isset() always exists and is not nullable.
------ -----------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 20 errors
Just two commands. # PHP 8.0
composer require --dev szepeviktor/phpstan-wordpress
vendor/bin/phpstan analyze -c vendor/szepeviktor/phpstan-wordpress/extension.neon -l 5 simple-page-ordering.php
Marked ones are resolved in PR-s. The ones mentioning |
On higher levels (6, 7, 8, 9) you have to supply more information to PHPStan in docblocks/typehints. |
@szepeviktor Running your command on this PR, I got this report
The first two are safe to ignore, but do you think we should fix the remaining? |
Please see #94 |
Description of the Change
Ran @phpstan and fixed reported problems.
Verification Process
Nope.
Checklist:
Changelog Entry
Fixed coding standards