Skip to content

fix(php): remove no-op Psalm flags, document PHPStan AgentDetector#1

Merged
alies-dev merged 3 commits into
mainfrom
fix/php-psalm-phpstan-accuracy
Apr 3, 2026
Merged

fix(php): remove no-op Psalm flags, document PHPStan AgentDetector#1
alies-dev merged 3 commits into
mainfrom
fix/php-psalm-phpstan-accuracy

Conversation

@alies-dev

Copy link
Copy Markdown
Owner

Summary

Tested all 6 PHP tools (PHPStan, Psalm, PHPUnit, PHPCS, PHP-CS-Fixer, Rector) on a real Laravel 12 codebase to validate the recommended flags.

Psalm — remove --monochrome and --show-snippet=false:

  • --monochrome: proved identical output with and without when using --output-format=text — the text formatter never emits ANSI codes
  • --show-snippet=false: proved identical output with and without when using --output-format=text — snippets only appear in the default console format

PHPStan — document AgentDetector (2.x):
PHPStan 2.x ships an AgentDetector (PHPStan\Internal\AgentDetector) that checks env vars (CLAUDECODE, CURSOR_TRACE_ID, OPENCODE, etc.) and injects:

  • A ~600-byte "Instructions for interpreting errors" preamble on every error-producing run
  • [identifier=...] suffixes on each error line in raw format

For 3 errors: 1420 bytes with agent detection vs 478 bytes without — 197% overhead from the preamble alone. This is the single largest source of token overhead in PHPStan output when running inside AI agents, and it applies regardless of --error-format.

Test plan

  • Verified Psalm --show-snippet=false is a no-op on text format (diff of outputs is empty)
  • Verified Psalm --monochrome is a no-op on text format (diff of outputs is empty)
  • Verified PHPStan AgentDetector source in phpstan.phar (src/Internal/AgentDetector.php)
  • Confirmed preamble disappears when CLAUDECODE env var is unset
  • Measured exact byte overhead (942 bytes for 3 errors)

Psalm: remove --monochrome and --show-snippet=false from text format
recommendations — both are no-ops when using --output-format=text
(text format never outputs ANSI colors or code snippets).

PHPStan: document the 2.x AgentDetector that injects a ~600-byte
preamble when it detects AI agent env vars (CLAUDECODE, CURSOR_TRACE_ID,
etc.), as this is a significant undocumented source of token overhead.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the PHP tooling guidance (php.md) to reduce no-op flags and document output overhead sources that matter for AI agent usage.

Changes:

  • Removed redundant Psalm flags (--monochrome, --show-snippet=false) when using --output-format=text.
  • Added documentation about PHPStan 2.x AgentDetector and its fixed preamble overhead in agent environments.
  • Updated the AGENTS.md / CLAUDE.md template snippet to match the revised Psalm command.

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

Comment thread php.md Outdated
Comment thread php.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


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

Comment thread php.md Outdated
@alies-dev alies-dev merged commit 289fdc2 into main Apr 3, 2026
1 check passed
@alies-dev alies-dev deleted the fix/php-psalm-phpstan-accuracy branch April 3, 2026 14:25
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