Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error identifiers #226

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

IanDelMar
Copy link
Contributor

This PR introduces rule error identifiers for the following rules:

  • IsWpErrorRule
  • HookDocsRule
  • HookCallbackRule

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:

  • Introduces constants to give meaning to certain numbers.
  • Reduces nesting level in HookCallbackRule::getAcceptedArgs().
  • Calls HookCallbackRule::validateActionReturnType() and HookCallbackRule::validateFilterReturnType() on the return type instead of on the callable acceptor.
  • Renames HookCallbackRule::isNever() to HookCallbackRule::isExplicitNever() to be more explicit about the method's functionality.

@szepeviktor
Copy link
Owner

Do we need to bump phpstan version?

@IanDelMar
Copy link
Contributor Author

IanDelMar commented Jun 26, 2024

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 szepeviktor merged commit 616bcb4 into szepeviktor:master Jun 26, 2024
1 of 2 checks passed
@szepeviktor
Copy link
Owner

Thank you, Ian.

@IanDelMar IanDelMar deleted the error-identifiers branch June 26, 2024 19:14
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