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

Introduce PHPStan for Static Analysis #213

Merged
merged 8 commits into from
Feb 10, 2025
Merged

Conversation

lloc
Copy link
Contributor

@lloc lloc commented Feb 3, 2025

This PR introduces PHPStan to improve static analysis for our codebase.

Changes in this PR

  • Added szepeviktor/phpstan-wordpress as a dev dependency.
  • Created phpstan.neon.dist with an initial configuration.
  • Added a Composer script (composer phpstan) for easy execution.
  • Changes in the code to address the issues reported by PHPStan.

Next Iterations

  • Raise rule levels ++ until target level.
  • Fix the reported errors.

Let me know your thoughts!

@lloc
Copy link
Contributor Author

lloc commented Feb 3, 2025

@JJJ @spacedmonkey This would need (even with the downgrade) PHP 7.2 at least.

@@ -11,7 +11,7 @@
*
* @since 1.3.0
*/
class WP_MS_Network_Command extends WP_CLI_Command {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Historically, WP-CLI provided a base WP_CLI_Command class to extend, however extending this class is not required and will not change how your command behaves.

https://make.wordpress.org/cli/handbook/guides/commands-cookbook/

@@ -260,7 +260,7 @@ public function list_( $args, $assoc_args ) {
* @param array $assoc_args Associative CLI arguments.
*/
public function plugin( $args, $assoc_args ) {
$this->fetcher = new \WP_CLI\Fetchers\Plugin();
$fetchers_plugin = new \WP_CLI\Fetchers\Plugin();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this should be a var and not a class member (PHPStan also didn't like it :-))

@@ -449,10 +449,6 @@ public function update_item( $request ) {
}

if ( ! empty( $prepared_args ) ) {
if ( is_wp_error( $prepared_args ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already sorted out at line 447.

@lloc
Copy link
Contributor Author

lloc commented Feb 4, 2025

@spacedmonkey I just added the GitHub action for PHPStan. This runs with PHP 7.2.

@lloc
Copy link
Contributor Author

lloc commented Feb 5, 2025

#214 removes the blocker for this PR.

Copy link
Contributor

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly recommeding doing a composer install and use the installed version of phpstan than using the existing action. That way all extensions are installed and same version on local as in CI.

I recommd following this guide on how to setup https://pascalbirchler.com/phpstan-wordpress/

@lloc
Copy link
Contributor Author

lloc commented Feb 6, 2025

I strongly recommeding doing a composer install and use the installed version of phpstan than using the existing action. That way all extensions are installed and same version on local as in CI.

I recommd following this guide on how to setup https://pascalbirchler.com/phpstan-wordpress/

The workflow has been changed now and is running as expected: https://github.com/lloc/wp-multi-network/actions/runs/13176556055/job/36777152590

@lloc lloc requested a review from spacedmonkey February 6, 2025 10:04
@JJJ JJJ merged commit c3e3b4a into stuttter:master Feb 10, 2025
1 check failed
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

Successfully merging this pull request may close these issues.

3 participants