szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
262 stars 26 forks source link

Add error identifiers #226

Closed IanDelMar closed 2 months ago

IanDelMar commented 2 months ago

This PR introduces rule error identifiers for the following rules:

The identifiers are sourced from the PHPStan code base, except for paramTag.count. PHPStan does not have a corresponding error identifier for this; there is arguments.count, but this handles arguments, not tags. If anyone has better ideas on how to name the identifiers, I am happy to change them.

For HookDocsRule and HookCallbackRule, this PR replaces the try-catch blocks with checks for existing errors in an array holding the errors and removes the exceptions since they are no longer used. Keeping the exceptions would have required different exceptions for each error identifier to retrieve the correct identifier if the exception is thrown.

Changes not related to error identifiers:

szepeviktor commented 2 months ago

Do we need to bump phpstan version?

IanDelMar commented 2 months ago

I don't think so. RuleErrorBuilder::message(...)->identifier(...) has been around for a while now. See this link. The new interface IdentifierRuleError extends RuleError and simply adds a method to retrieve the identifier. Older versions of PHPStan don't know about this interface and do not use the getIdentifier() method. Newer versions of PHPStan complain about using the RuleError interface instead of the IdentifierRuleError interface.

It should be sufficient to ignore these errors.

However, we should be considerate about identifier names. If people use the identifiers to ignore errors, they won't be happy if the identifiers change.

szepeviktor commented 2 months ago

Thank you, Ian.