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 ExceptionList property for UnusedFormalParameter #984

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PedroPMS
Copy link

Type: feature

This PR add the exception property to the UnusedFormalParameter rule.

Some classes of some frameworks, such as Laravel ApiResource, uses some parameters that arent used by the method.

image

@AJenbo
Copy link
Member

AJenbo commented Sep 23, 2022

Isn't that then a fault with the class, correctly detected by PHPMD. and should be corrected instead of ignored?

@PedroPMS
Copy link
Author

PedroPMS commented Sep 23, 2022

Isn't that then a fault with the class, correctly detected by PHPMD. and should be corrected instead of ignored?

Yeah, is a fault with the class, but the entire framework uses like this. So we can only ask for a fix in the framework and implement a exception list in PHMD 🤷‍♂️

@AJenbo
Copy link
Member

AJenbo commented Sep 23, 2022

Maybe a better solution is to have a setting to ignore violations that are inherited?

@kylekatarnls
Copy link
Member

IIRC it's a method_exists($class, 'toArray') trick used from Laravel side, so no inheritence. I'm in favor of an unified exceptions option available in all the rules anyway.

@tvbeek
Copy link
Member

tvbeek commented Sep 24, 2022

In this case I should remove the request because it isn't required to have. (I have changed it in my stubs)
If that wasn't possible I should add an unset call on the first line of the function to be clear that it isn't used. Another option is to add a suppress comment.

A generic rule means that you have more change to hide a place where it should notice about a problem.

@AJenbo
Copy link
Member

AJenbo commented Sep 24, 2022

IIRC it's a method_exists($class, 'toArray') trick used from Laravel side, so no inheritence. I'm in favor of an unified exceptions option available in all the rules anyway.

If that is the case then there is no reason to actually have the unused argument. PHP doesn't have function overloading so if Laravel is calling the function with more arguments then it has it will still work the same.

@PedroPMS
Copy link
Author

PedroPMS commented Sep 26, 2022

As you guys said, there are other ways to suppress this warning, suppress comment, ignore inherited and others. The exception property is just one more option that anybody can use as they wish. This feature has no breaking changes.

@Sandant589
Copy link

Ok

@kylekatarnls
Copy link
Member

Handling inheritance better does not prevent to have an list for exceptions.

This PR still need to have documentation update and unit tests. If so I would approve. @AJenbo @tvbeek @ravage84 Are you fine with that? Let's have a definitive go/no-go decision so either we define what it needs to be merged, or we close.

Copy link
Member

@ravage84 ravage84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's pointless to fight bad framework design and people potentially shooting themselves in the foot, we can add this.

But it needs docs, tests etc as usual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

6 participants