Skip to content

Add phpstan and Resolve issues#666

Open
bhavz-10 wants to merge 10 commits intotheme-elementary-v2from
feature/issue-634-add-phpstan
Open

Add phpstan and Resolve issues#666
bhavz-10 wants to merge 10 commits intotheme-elementary-v2from
feature/issue-634-add-phpstan

Conversation

@bhavz-10
Copy link
Copy Markdown

@bhavz-10 bhavz-10 commented Apr 15, 2026

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

@bhavz-10 bhavz-10 changed the title feat: add phpstan and resolve issues Add phpstan and Resolve issues Apr 22, 2026
@bhavz-10 bhavz-10 marked this pull request as ready for review April 22, 2026 11:30
@bhavz-10 bhavz-10 self-assigned this Apr 22, 2026
@bhavz-10 bhavz-10 marked this pull request as draft April 22, 2026 11:30
@bhavz-10 bhavz-10 marked this pull request as ready for review April 22, 2026 11:44
Copy link
Copy Markdown

@Adi-ty Adi-ty left a comment

Choose a reason for hiding this comment

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

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.

Comment thread inc/Framework/Traits/Singleton.php Outdated
Comment thread phpstan-baseline.neon
@bhavz-10
Copy link
Copy Markdown
Author

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:

  • Adjustability: We can always reduce the strictness later if it causes a nuisance.
  • Customization: Users can still use the baseline for their own custom setups.
  • Visibility: Rather than decreasing the level to hide issues, we will maintain a baseline with documented errors. This ensures they are tracked and can be resolved at a later point.

Comment thread inc/Modules/BlockExtensions/MediaTextInteractive.php Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 phpstan script.
  • 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.

Comment thread phpstan.neon.dist
Comment thread phpstan.neon.dist Outdated
- tests/
- vendor/
analyseAndScan:
- node_modules (?)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
- node_modules (?)
- node_modules/

Copilot uses AI. Check for mistakes.
Comment thread phpstan.neon.dist
- vendor/
analyseAndScan:
- node_modules (?)
scanFiles:
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
scanFiles:
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread composer.json
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.

4 participants