phpstan: Add Error identifiers

Feature request

In PHP Insights we tried to add support for phpstan, however we ran into some problems doing so.
A way we were looking into was by creating a custom ErrorFormatter, however in PHP Insights, we categorize issues by which insight the issue came from (where in the case of phpstan an insight would be a rule).
This means for us to add support by using a ErrorFormatter, the Error class would have to know which rule it was that the error came from.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 19
  • Comments: 24 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve made huge progress on error identifiers recently! All rules in PHPStan core and in all 1st party extensions are now labeled with error identifiers.

Here’s the complete list (automatically extracted & always up-to-date): https://phpstan.org/error-identifiers

I believe I can close this now.

Before PHPStan 1.11 there’s still more to do, most significantly: https://github.com/phpstan/phpstan/issues/3296

But you can already query identifiers in custom error formatters.

@ondrejmirtes OK, can you assign me here? I will work on the proposal and would like to work on implementation 🙂

There needs to be some upfront plan about how the identifiers need to be structured, so I’d like to hear that plan.

After we agree how these are named, someone needs to go through all the rules and call ->identifier(‘abc’) on the RuleErrorBuilder.

Remember, these identifiers don’t (and shouldn’t) be 1:1 with current rule classes. There can be situations where the same identifier is used across multiple rule classes, and there can be situations where a single rule class reports different identifiers.

We shouldn’t too overgineer it because they’ll probably be part of user-facing UI, in configuration files, local ignore annotations etc…

Yes, that’s the idea. But it’s not in the immediate roadmap, but I’d like to get to it in the next 12 months.

I generally don’t work with issue assignees on GitHub. Feel free to work on it 👍

Personally I would love to see this feature. Ignoring system is one of few things that I dislike in PHPStan, it would be much better to be able to operate on identifiers instead of error messages.

@ondrejmirtes I would be open to help with it, but we should discuss it and create some roadmap. What do you think?