Fix #184: Check FormTypeInterface instead of class name suffix#185
Fix #184: Check FormTypeInterface instead of class name suffix#185gchehami wants to merge 1 commit intophp-translation:masterfrom
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? |
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 |
|
Hm, the latest changes caused errors in CI, could you double-check? It should be something minor I suppose |
ad1c4c3 to
d825b52
Compare
…nterface instead of checking the classname to determinate if the class is a form fix phpstan Call to an undefined method PhpParser\ParserFactory::createForVersion()
|
Hello, so i tried the first solution and it was good if the first class implements the interface but if the class extends another class that implements the interface then the first class was not detected has formType so i improve the code to get the interface of extended classes with récursive call to get all the interfaces and be sure one of them has FormTypeInterface. i Also add some Unit Test to validate. I think i have the good solution now. |
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