-
Notifications
You must be signed in to change notification settings - Fork 34
Fix #184: Check FormTypeInterface instead of class name suffix #185
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
base: master
Are you sure you want to change the base?
Conversation
|
Yeah, you're right, checking for the interface is much better... I would say maybe we should drop the legacy way of checking for Also, could you please check the failed SA tools? |
| if ($node instanceof Stmt\Class_) { | ||
| $this->isFormType = 'Type' === substr($node->name, -4); | ||
| $this->isFormType = 'Type' === substr($node->name, -4) || in_array( | ||
| 'Symfony\Component\Form\FormTypeInterface', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use FormTypeInterface::class here instead of the string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use FormTypeInterface::class here instead of the string you need to have the symfony/form package installed as a dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's keep it simple for now
I initially considered this approach, but a colleague pointed out that it could be a breaking change for users who have classes ending with "Type" that don't implement the interface. i check for the failed SA tools |
Hm, but we're talking about forms here, and you always have to implement that interface for your form types, right? If so, I would not consider it as the BC break actually. I can't think of when you have a form type but don't extend that interface. Do you have any use cases for this? |
No i don't have any use case for this so okay i remove the check |
…nterface instead of checking the classname to determinate if the class is a form
Description
This PR fixes the form detection logic to check if a class implements
FormTypeInterfaceinstead of checking if the class name ends with "Type" only.Fixes #184
Changes
FormTrait.phpto check forFormTypeInterfaceimplementationMyForm,MyFormType,CustomFormType)Motivation
There are no rules that impose naming forms with the word "Type" at the end of classnames. Developers may name their forms with different suffixes like "Form" or any other convention. The correct way is to check if the class implements the
FormTypeInterface.Testing