Skip to content

Comments

Fix #184: Check FormTypeInterface instead of class name suffix#185

Open
gchehami wants to merge 1 commit intophp-translation:masterfrom
gchehami:issue-184
Open

Fix #184: Check FormTypeInterface instead of class name suffix#185
gchehami wants to merge 1 commit intophp-translation:masterfrom
gchehami:issue-184

Conversation

@gchehami
Copy link

@gchehami gchehami commented Jan 27, 2026

Description

This PR fixes the form detection logic to check if a class implements FormTypeInterface instead of checking if the class name ends with "Type" only.

Fixes #184

Changes

  • Modified FormTrait.php to check for FormTypeInterface implementation
  • Now supports forms with any naming convention (e.g., MyForm, 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

  • Existing tests should pass
  • Forms not ending with "Type" are now correctly detected

@bocharsky-bw
Copy link
Member

Yeah, you're right, checking for the interface is much better... I would say maybe we should drop the legacy way of checking for Type suffix in favor of your way based on the interface implementation? WDYT?

Also, could you please check the failed SA tools?

@gchehami
Copy link
Author

Yeah, you're right, checking for the interface is much better... I would say maybe we should drop the legacy way of checking for Type suffix in favor of your way based on the interface implementation? WDYT?

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

@bocharsky-bw
Copy link
Member

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.

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?

@gchehami
Copy link
Author

gchehami commented Jan 28, 2026

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.

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

@bocharsky-bw
Copy link
Member

Hm, the latest changes caused errors in CI, could you double-check? It should be something minor I suppose

@gchehami gchehami force-pushed the issue-184 branch 2 times, most recently from ad1c4c3 to d825b52 Compare February 19, 2026 11:23
…nterface instead of checking the classname to determinate if the class is a form

fix phpstan Call to an undefined method PhpParser\ParserFactory::createForVersion()
@gchehami
Copy link
Author

gchehami commented Feb 20, 2026

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.

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 this pull request may close these issues.

Symfony FormTrait: should check instanceof instead of name

2 participants