Skip to content

Remove redundant is_array() check flagged by PHPStan - #678

Merged
swissspidy merged 1 commit into
wp-cli:mainfrom
ekamran:shifteq/phpstan-static-variables
Nov 1, 2026
Merged

swissspidy merged 1 commit into
wp-cli:mainfrom
ekamran:shifteq/phpstan-static-variables

Conversation

@ekamran

@ekamran ekamran commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The PHPStan check has failed on main and on every pull request since 2026-10-28, including #676 and #677:

 696    Call to function is_array() with array will always evaluate to true.
        🪪  function.alreadyNarrowedType

ReflectionFunctionAbstract::getStaticVariables() always returns an array, so the is_array() check on its result in update_commands_data() is redundant. PHPStan reports it starting with 2.3.3. The repository has no composer.lock, so CI installs the newest PHPStan: the last green run on main used 2.3.2, and the first failing run used 2.3.3.

Changes

  • Drop the redundant is_array( $static ) condition in bin/Handbook_Command.php. No behavior change.

Verification

  • composer phpstan with PHPStan 2.3.4: 1 error on main, no errors with this change.
  • composer phpstan with PHPStan 2.3.2: no errors with or without this change.
  • PHPCS: no errors in bin/Handbook_Command.php.

Use of AI

AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: tracing the CI failure to the PHPStan update, testing the fix with both PHPStan versions, drafting the change, and reviewing it. I reviewed the reasoning and test results, and I take responsibility for the contribution.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of command metadata when determining whether a command can be called. This is an internal reliability adjustment; no new user-facing capabilities or changes to the available commands are included in this update.

ReflectionFunctionAbstract::getStaticVariables() always returns an
array, so checking its result with is_array() is redundant. PHPStan
2.3.3 and newer report it as function.alreadyNarrowedType, which fails
the PHPStan check on main and on every pull request.
@ekamran
ekamran requested a review from a team as a code owner November 1, 2026 15:27
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1eb52abd-eb26-49ac-9a09-060ca5f8a727
Commits

Reviewing files that changed from the base of the PR and between 4d4fb89 and d1f4faf.

Files selected for processing: 1
  • bin/Handbook_Command.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

update_commands_data() no longer checks whether the closure’s static variables are an array before checking for a callable entry.

Changes: Command data update

Layer / File(s) Summary
Check callable entry
bin/Handbook_Command.php
update_commands_data() removes the is_array() guard before checking for a callable entry.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Refactor

Suggested reviewers: gitlost

Merge Risk: Minimal · up to d1f4f

The change addresses the static-analysis warning without altering reachable behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: removing the redundant is_array() check identified by PHPStan.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

PHPStan (2.3.1)

Invalid configuration:
Unexpected item 'parameters › strictRules'.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@swissspidy
swissspidy merged commit f42e382 into wp-cli:main Nov 1, 2026
8 checks passed
@ekamran
ekamran deleted the shifteq/phpstan-static-variables branch November 1, 2026 19:14
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.

2 participants