Skip to content

Fix phpstan/phpstan#14443: bisect command#5431

Merged
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-rykz2pn
Apr 8, 2026
Merged

Fix phpstan/phpstan#14443: bisect command#5431
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-rykz2pn

Conversation

@phpstan-bot
Copy link
Copy Markdown
Collaborator

Summary

Implements a new phpstan bisect command that performs a git-bisect-like binary search over PHPStan releases to find the first commit that introduced a regression. This is useful for debugging regressions that are only reproducible with complex project configurations where using phpstan-src directly isn't feasible.

Changes

  • Added src/Command/BisectCommand.php — new Symfony Console command implementing the bisect workflow
  • Updated bin/phpstan to register the new BisectCommand
  • Added tests/PHPStan/Command/BisectCommandTest.php with tests for command configuration, GitHub token resolution, argument building, and non-interactive error handling

How it works

  1. User runs phpstan bisect and provides a "good" (working) and "bad" (broken) release version, either via --good/--bad options or interactively
  2. The command queries the GitHub Compare API to get all commits between the two releases in phpstan/phpstan
  3. It performs binary search: for each midpoint commit, it downloads the corresponding phpstan.phar from raw.githubusercontent.com, runs analysis, and asks the user whether the result is "good" or "bad"
  4. When the search converges, it prints the first bad commit along with its full message, which typically includes links to the phpstan-src commits that were pushed together

Key design decisions

  • GitHub token is resolved from GITHUB_TOKEN/GH_TOKEN env vars (CI-friendly) or ~/.composer/auth.json (developer-friendly)
  • Downloaded phars are cached in sys_get_temp_dir()/phpstan-bisect/ to avoid re-downloading on repeated bisect runs
  • Supports forwarding common analyse options (-c, -l, -a, --memory-limit, paths) to the downloaded phar
  • The command doesn't need CommandHelper::begin() or the DI container since it runs external phar processes

Test

BisectCommandTest verifies:

  • Command is properly configured with all expected options and arguments
  • Non-interactive mode returns error when --good/--bad are missing
  • GitHub token reading from auth.json file
  • GitHub token reading from environment variables
  • Token returns null when no source is available
  • buildAnalyseArgs correctly builds the command-line string from input options

Fixes phpstan/phpstan#14443

ondrejmirtes and others added 3 commits April 8, 2026 14:25
- New `phpstan bisect` command that performs binary search between two releases
- Downloads phpstan.phar for each tested commit from the phpstan/phpstan repo
- Queries GitHub API (Compare endpoint) for commit list between releases
- Reads GitHub token from GITHUB_TOKEN/GH_TOKEN env vars or ~/.composer/auth.json
- Runs analysis with downloaded phar and asks user if result is good or bad
- Reports first bad commit with phpstan-src commit links from commit description
- Tests for command configuration, token reading, and argument building
@ondrejmirtes ondrejmirtes merged commit ae20323 into phpstan:2.1.x Apr 8, 2026
1296 of 1306 checks passed
@ondrejmirtes ondrejmirtes deleted the create-pull-request/patch-rykz2pn branch April 8, 2026 17:00
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