Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix WI-58890#9

Open
jasekiw wants to merge 3 commits intoJetBrains:masterfrom
jasekiw:fix-phpstan-paths
Open

Fix WI-58890#9
jasekiw wants to merge 3 commits intoJetBrains:masterfrom
jasekiw:fix-phpstan-paths

Conversation

@jasekiw
Copy link

@jasekiw jasekiw commented Jan 12, 2026

Add PHPStan Editor Mode Support

Fixes: WI-58890

Summary

This PR adds support for PHPStan's editor mode, which resolves issues with ignoreErrors configuration not working correctly during on-the-fly analysis in PhpStorm.

  • Fix file mapping for temp files: When PhpStorm performs on-the-fly analysis, it creates temporary copies of files. PHPStan's ignoreErrors rules (configured in phpstan.neon) match against file paths, so errors that should be ignored based on the original file path were incorrectly being reported because PHPStan saw the temp file path instead.

  • Add version detection: Editor mode (--tmp-file / --instead-of CLI options) is only available in PHPStan 1.12.27+ and 2.1.17+. The plugin now detects the PHPStan version and only enables editor mode when supported.

Changes

File Mapping (PhpStanAnnotatorProxy.java)

  • Track original file paths when creating temp files for analysis
  • Map temp file paths back to original paths during command construction

Editor Mode Command Options (PhpStanGlobalInspection.java)

  • New getCommandLineOptions() overload for editor mode that uses:
    • --tmp-file <temp-path> - specifies the temp file containing current editor content
    • --instead-of <original-path> - tells PHPStan to treat errors as coming from the original path
  • Falls back to standard behavior when editor mode is not supported
  • Auto detects the version on first run so plugin upgrade is seamless.

Version Support (PhpStanVersionSupport.java)

  • New utility class for PHPStan version detection and comparison
  • extractVersionFromOutput() - parses version string from PHPStan output
  • supportsEditorMode() - checks version compatibility (1.12.27+ or 2.1.17+)
  • detectVersion() - runs phpstan --version for auto-detection

Configuration Changes

  • PhpStanConfiguration.java - stores detected PHPStan version
  • PhpStanConfigurableForm.java - captures version during tool validation

Note: I had to rebuild the gradle build system for this repo since there didn't seem to be any build system in place. I left that on a separate branch to avoid adding more than the fix to this pull request.

Test Plan

I need guidance on testing. I tested it with my local phpstorm and it worked.

This is the test plan I came up with:

  • Verify on-the-fly analysis works with PHPStan 1.12.27+
  • Verify on-the-fly analysis works with PHPStan 2.1.17+
  • Verify ignoreErrors rules in phpstan.neon are respected during on-the-fly analysis
  • Verify fallback behavior for older PHPStan versions (< 1.12.27 / < 2.1.17)
  • Verify version detection works when configuring PHPStan path in settings

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.

1 participant