Skip to content

Linting tools: add PHPStan#26

Open
jeherve wants to merge 1 commit into
trunkfrom
add/phpstan
Open

Linting tools: add PHPStan#26
jeherve wants to merge 1 commit into
trunkfrom
add/phpstan

Conversation

@jeherve

@jeherve jeherve commented Nov 26, 2021

Copy link
Copy Markdown
Owner

Changes proposed in this Pull Request:

- Linting: add PHPStan tools to analyze the codebase

  • Avoid issues with custom apply_filters
  • Fix level 4 issues
  • Add PHPStan to linting action

A few notes:

  • When trying to use PHPStan's options to ignore specific lines, I kept getting memory fatal errors. So I had to make those ignore rules in the config file instead.
  • When trying to up the config to level 5, I keep running into the same memory Fatals locally. I may try it in the CI though.

Edit: I see I get the same fatals in the CI already, even at level 4:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///home/runner/work/posts-on-this-day/posts-on-this-day/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Lexer.php on line 263
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///home/runner/work/posts-on-this-day/posts-on-this-day/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Lexer.php on line 263
Script ./vendor/bin/phpstan analyze -c phpstan.neon.dist --memory-limit 128M handling the phpstan event returned with error code 255

Testing instructions:

  • Do the tests pass?

@jeherve jeherve changed the base branch from master to trunk December 17, 2025 12:53
@jeherve jeherve requested a review from Copilot December 17, 2025 12:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds PHPStan static analysis tooling to the WordPress plugin codebase to improve code quality and catch potential issues. The implementation includes PHPStan at level 4 with WordPress-specific extensions and integrates it into the existing CI/CD pipeline.

  • Adds PHPStan 2.1.33 along with WordPress-specific extensions for static analysis
  • Fixes PHPStan level 4 issues by adding missing return type documentation
  • Integrates PHPStan into GitHub Actions workflow with memory limits to handle analysis requirements

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
phpstan.neon.dist New PHPStan configuration file setting level 4 analysis for src and tests directories
composer.json Adds PHPStan dependencies and creates phpstan script with memory limit configuration
composer.lock Updates lock file with PHPStan and WordPress stubs dependencies
src/class-posts-on-this-day-widget.php Adds @return void and @return string|void documentation for widget methods
.github/workflows/lint.yml Adds new phpstan job to run static analysis in CI with 5-minute timeout
.gitattributes Adds phpstan.neon.dist to export-ignore list and reformats for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread composer.json
],
"phpstan": [
"Composer\\Config::disableProcessTimeout",
"@composer update",

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The phpstan script includes a composer update command which may cause unexpected dependency updates during static analysis. PHPStan should run against the current dependency state without updating packages. Consider removing the "@composer update" line to avoid unintended side effects during static analysis runs.

Suggested change
"@composer update",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants