10up / simple-page-ordering

Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
https://wordpress.org/plugins/simple-page-ordering/
GNU General Public License v2.0
149 stars 23 forks source link

Fix problems reported by static analysis #93

Closed szepeviktor closed 2 years ago

szepeviktor commented 2 years ago

Description of the Change

Ran @phpstan and fixed reported problems.

Verification Process

Nope.

Checklist:

Changelog Entry

Fixed coding standards

szepeviktor commented 2 years ago

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
 ------ -----------------------------------------------------------------------------------------------
  Line   simple-page-ordering.php
 ------ -----------------------------------------------------------------------------------------------
  32     Class Simple_Page_Ordering referenced with incorrect case: Simple_page_Ordering. 👈
  77     Function apply_filters invoked with 3 parameters, 2 required.
  191    Method Simple_Page_Ordering::page_ordering() has invalid return type obj. 👈
  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. 👈
  408    Function apply_filters invoked with 3 parameters, 2 required.
  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. 👈
 ------ -----------------------------------------------------------------------------------------------

Marked ones are resolved in PR-s. The ones mentioning apply_filters could be ignored.

szepeviktor commented 2 years ago

On higher levels (6, 7, 8, 9) you have to supply more information to PHPStan in docblocks/typehints.

dinhtungdu commented 2 years ago

Just two commands.

@szepeviktor Running your command on this PR, I got this report

 ------ ---------------------------------------------------------------- 
  Line   simple-page-ordering.php                                        
 ------ ---------------------------------------------------------------- 
  77     Function apply_filters invoked with 3 parameters, 2 required.   
  408    Function apply_filters invoked with 3 parameters, 2 required.   
  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.  
 ------ ---------------------------------------------------------------- 

The first two are safe to ignore, but do you think we should fix the remaining?

szepeviktor commented 2 years ago

The first two are safe to ignore, but do you think we should fix the remaining?

Please see https://github.com/10up/simple-page-ordering/pull/94