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 #41

Closed
InvisibleSmiley opened this issue Sep 16, 2024 · 2 comments · Fixed by #43
Closed

Add error identifiers #41

InvisibleSmiley opened this issue Sep 16, 2024 · 2 comments · Fixed by #43

Comments

@InvisibleSmiley
Copy link

Situation

I'm in a situation where I want to enable some/all checks this extension provides in general, but ignore specific cases.

Right now I can only use the old approach of either ignoring by regex via config or baseline, or add generic "ignore anything here" @phpstan-ignore-line/@phpstan-ignore-next-line comments.

What I want is to explicitly ignore a certain rule in specific places (see use case below).

For that I'd need support of error identifiers (e.g. type_perfect.narrow_return), cf.:
https://phpstan.org/blog/phpstan-1-11-errors-identifiers-phpstan-pro-reboot

Use Case

I have a class that has properties with mutable types (interfaces containing methods that allow object mutation).
On the same class I have methods that return these properties but use immutable return types (interfaces that do not advertise methods capable of object mutation). These cases are correctly detected by narrow_return but I want to ignore these specific cases.

@TomasVotruba
Copy link
Member

Thanks for the suggestions. It looks good to me 👍 Could you send PR?

@InvisibleSmiley
Copy link
Author

Could you send a PR?

I probably could but it's really not that hard given that you already require PHPStan ^1.11 (so error identifiers support is there and you don't need to support older versions that don't have it).

It's as simple as calling identifier('X') in the right places, cf.
https://phpstan.org/error-identifiers (includes links to PHPStan sources).

SanderMuller added a commit to SanderMuller/type-perfect that referenced this issue Sep 17, 2024
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 a pull request may close this issue.

2 participants