-
Notifications
You must be signed in to change notification settings - Fork 483
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
Introduce IgnoreErrorExtension #3783
base: 2.1.x
Are you sure you want to change the base?
Conversation
Hi, this is exactly what I'm looking for right now as I'm working on Magento 2 projects when I'm bit of forced into following error:
I do not want to ignore all missingType.parameter errors in I'd use this proposed feature or I can use configuration with something like this:
And for the requirement to have strongly typed first argument and ignore error based on that - I can then create custom rule to check this condition. Maybe you can do that too in your case. |
@LoogleCZ Yes, with this extension you would be able to filter errors based on their class, namespace, if they use an attribute, if this extend from some base class, etc... Curious what Ondrej thinks about it 😊 |
Yeah, this would be a nice addition. But there's a lot of details that we need to get right (because ignoring errors is one of the most popular and most widely used PHPStan feature!). Some notes I have after thinking about this:
|
Sure
If we would first want to process the ignoreErrors, then the current place where I call the extension does not make sense. How would we be able to get the Node at the ignoreErrors stage? I think that information is not part of the Error, right? Is it even possible to put the Node in the Error, and restore that from the result cache?
Sure, we can first call the RuleErrorTransformer and then pass the Error to the filter.
Will take care of this later once we iron out 2 + 3 😉 |
Yeah, if you need to access |
So to summarize:
Thank you! |
This allows for more flexibility in ignoring errors. Some use cases: * Ignore `missingType.iterableValue` on controller actions: Rule: when the method is public and it has `#[Route]` attribute or the class has `#[AsController]` attribute. * Ignore `should return int but returns int|null` on `getId` for entities. Rule: class needs to have `#[Entity]` attribute. * Ignore `never returns null so it can be removed from the return type` Rule: method needs to have `#[GraphQL\Field]` attribute. * Enforce missingCheckedExceptionInThrows partially, only for specific classes.
702d577
to
f7021e9
Compare
I pushed the requested changes, please have a look when you have time. When you think it looks OK, I will continue with adding tests and tweaking things. |
This allows for more flexibility in ignoring errors.
Some use cases:
missingType.iterableValue
on controller actions:Rule: when the method is public and it has
#[Route]
attribute or theclass has
#[AsController]
attribute.should return int but returns int|null
ongetId
for entities.Rule: class needs to have
#[Entity]
attribute.never returns null so it can be removed from the return type
Rule: method needs to have
#[GraphQL\Field]
attribute.This idea came from phpstan/phpstan#11134
Note
@ondrejmirtes Before I continue with adding tests and improving things, I would first like to know if agree with this functionality.