Add phpstan and Resolve issues#666
Conversation
Adi-ty
left a comment
There was a problem hiding this comment.
The issue mentions that level 5 is the target and that any pre-existing issues should be handled via a baseline rather than lowering the level. Moving to level 8 feels like a fairly meaningful step up in strictness, so I wanted to check whether that was intentional. If it was, could we call that out explicitly and get sign-off on the tighter standard? Otherwise, it may make sense to keep this at level 5 for now and rely on the baseline as described in the issue.
Hello @aryanjasala Why we should take a stricter approach:
|
There was a problem hiding this comment.
Pull request overview
Adds PHPStan static analysis tooling to the theme-elementary theme and updates a few PHPDoc/type-related issues to make the codebase analyzable.
Changes:
- Introduces PHPStan configuration (
phpstan.neon.dist), baseline, and bootstrap constants file. - Adds PHPStan + WordPress-related static analysis dependencies and a
composer phpstanscript. - Adjusts several PHPDoc/type hints and minor logic to satisfy static analysis.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
phpstan.neon.dist |
Adds PHPStan config (level, bootstrap, paths, excludes, scanned stubs). |
phpstan-bootstrap.php |
Provides theme constants for PHPStan bootstrap. |
phpstan-baseline.neon |
Adds baseline file to ignore pre-existing issues. |
composer.json |
Adds PHPStan + WP extensions/stubs and a phpstan composer script. |
composer.lock |
Locks newly added PHPStan/WP stub dependencies. |
inc/Framework/Traits/AssetLoaderTrait.php |
Tightens PHPDoc types and fixes pathinfo() usage for asset meta lookup. |
inc/Framework/Traits/Singleton.php |
Improves PHPStan typing for singleton instance storage/return. |
inc/Core/Assets.php |
Tightens PHPDoc and removes redundant array check. |
inc/Modules/BlockExtensions/MediaTextInteractive.php |
Tightens PHPDoc types and adjusts module dependency structure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - tests/ | ||
| - vendor/ | ||
| analyseAndScan: | ||
| - node_modules (?) |
There was a problem hiding this comment.
excludePaths.analyseAndScan contains node_modules (?), which doesn’t match a real directory name in this repo and is likely a leftover placeholder. This won’t actually exclude node_modules/ from scanning; update it to the correct path/pattern (or remove it if unnecessary).
| - node_modules (?) | |
| - node_modules/ |
| - vendor/ | ||
| analyseAndScan: | ||
| - node_modules (?) | ||
| scanFiles: |
There was a problem hiding this comment.
To satisfy the requirement that the config uses WordPress-specific stubs, consider explicitly scanning the WordPress stubs file as well (currently only the WP-CLI stubs file is scanned). Relying solely on transitive/extension loading can make it less obvious why WordPress symbols resolve in analysis.
| scanFiles: | |
| scanFiles: | |
| - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php |
Description
Setup phpstan for the theme.
Technical Details
Adding phpstan setup along with the baseline setup so that errors that are to be ignored can be added and setup a baseline again.
Checklist
Screenshots
To-do
Fixes/Covers issue
Fixes #634