Skip to content

Add initial PHPStan config#218

Merged
swissspidy merged 16 commits intomainfrom
fix/phpstan
Apr 8, 2026
Merged

Add initial PHPStan config#218
swissspidy merged 16 commits intomainfrom
fix/phpstan

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions bot added the scope:testing Related to testing label Apr 2, 2026
@github-actions

This comment was marked as resolved.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 75.30864% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Profiler.php 69.15% 33 Missing ⚠️
src/Formatter.php 80.55% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review April 8, 2026 11:18
@swissspidy swissspidy requested a review from a team as a code owner April 8, 2026 11:18
Copilot AI review requested due to automatic review settings April 8, 2026 11:18
@swissspidy swissspidy added this to the 2.1.7 milestone Apr 8, 2026
Copy link
Copy Markdown
Contributor

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

This PR introduces an initial PHPStan setup for the package and adjusts the codebase (mainly via typing/docblocks and a few runtime guards) to satisfy stricter static analysis.

Changes:

  • Add a phpstan.neon.dist configuration and a small scan bootstrap file under tests/phpstan/.
  • Improve PHPStan compatibility by adding/adjusting PHPDoc types and some defensive type checks across Profiler/Logger/Formatter/Command.
  • Introduce typed assoc-args handling in Command to better align with Utils\get_flag_value() expectations.

Reviewed changes

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

Show a summary per file
File Description
phpstan.neon.dist Adds baseline PHPStan configuration (level, paths, scanned stubs/files).
tests/phpstan/scan-files.php Provides scan-time constants to satisfy static analysis.
src/Profiler.php Adds PHPDoc types and runtime guards; refactors hook wrapping/tick profiling logic for static analysis.
src/Logger.php Adds PHPDoc typing + class-level documentation for dynamic properties.
src/Formatter.php Adds PHPDoc typing and stricter input normalization for fields/ordering.
src/Command.php Adds PHPDoc typing and a helper to normalize assoc args for PHPStan/flag parsing.

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

Comment on lines +327 to +332
$args = func_get_args();
if ( is_callable( $func ) ) {
$value = call_user_func_array( $func, $args );
} else {
$value = null;
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In wrap_current_filter_callbacks(), the wrapper now returns null when $func is not callable. That changes WordPress semantics: an uncallable hook callback would normally trigger a runtime error, but under profiling it would silently continue and potentially alter filter values. Consider removing the is_callable() branch and always invoking the original callback so behavior matches non-profiled execution (or, if you want to keep the guard, preserve the original filter value and surface a warning/error instead of returning null).

Suggested change
$args = func_get_args();
if ( is_callable( $func ) ) {
$value = call_user_func_array( $func, $args );
} else {
$value = null;
}
$args = func_get_args();
$value = call_user_func_array( $func, $args );

Copilot uses AI. Check for mistakes.
@swissspidy swissspidy merged commit 47fc059 into main Apr 8, 2026
61 of 62 checks passed
@swissspidy swissspidy deleted the fix/phpstan branch April 8, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants