Skip to content

Add initial PHPStan config#154

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

Add initial PHPStan config#154
swissspidy merged 14 commits intomainfrom
fix/phpstan

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

@github-actions

This comment was marked as resolved.

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

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 39.40887% with 123 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
inc/RestCommand.php 38.66% 92 Missing ⚠️
inc/Runner.php 41.50% 31 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a PHPStan configuration and adds comprehensive PHPDoc type hints to improve static analysis. Key changes include refactoring the diff_items logic to be more explicit, replacing manual WP_INSTALLING constant checks with the wp_installing() function, and correcting the casing of the RestCommand class instantiation. A regression was identified in inc/RestCommand.php where removing the reference operator from the $assoc_args parameter in get_formatter prevents the Formatter from correctly modifying the arguments array as expected by WP-CLI.

@swissspidy swissspidy marked this pull request as ready for review April 7, 2026 10:32
@swissspidy swissspidy requested a review from a team as a code owner April 7, 2026 10:32
Copilot AI review requested due to automatic review settings April 7, 2026 10:32
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

Adds an initial PHPStan configuration for the package and updates REST CLI runtime code with additional type checks/guards to satisfy higher static-analysis strictness.

Changes:

  • Add phpstan.neon.dist with level 9 analysis targeting inc/ and wp-rest-cli.php, scanning WP-CLI sources and WordPress stubs.
  • Harden Runner route discovery/registration with additional validation and updated debug/error messaging.
  • Add/adjust phpdoc types and runtime guards in RestCommand for safer handling of decoded JSON, CLI args, and REST responses.

Reviewed changes

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

File Description
phpstan.neon.dist Introduces baseline PHPStan configuration for the project.
inc/Runner.php Adds stricter validation/typing around REST index parsing and route registration.
inc/RestCommand.php Adds extensive type guards and phpdoc to reduce PHPStan findings and avoid notices.

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

Comment on lines +111 to 121
$count = 0;
if ( isset( $assoc_args['count'] ) ) {
$count = is_numeric( $assoc_args['count'] ) ? (int) $assoc_args['count'] : 0;
}
unset( $assoc_args['count'] );
$format = $assoc_args['format'];

$format = 'ids';
if ( isset( $assoc_args['format'] ) ) {
$format = is_scalar( $assoc_args['format'] ) ? (string) $assoc_args['format'] : 'ids';
}
unset( $assoc_args['format'] );
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

generate_items() falls back to count=0 and format='ids' when assoc args are missing, but the command synopsis in Runner::register_route_commands() documents defaults of count=10 and format='progress'. Align these defaults (or explicitly rely on WP-CLI to inject synopsis defaults) to avoid surprising behavior when options aren’t provided.

Copilot uses AI. Check for mistakes.
swissspidy and others added 2 commits April 8, 2026 14:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy added this to the 0.4.2 milestone Apr 8, 2026
@swissspidy swissspidy mentioned this pull request Apr 8, 2026
@swissspidy swissspidy merged commit 46e1550 into main Apr 8, 2026
87 of 139 checks passed
@swissspidy swissspidy deleted the fix/phpstan branch April 8, 2026 20:52
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