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

False positive with Symfony Forms #12

Open
aturki opened this issue Sep 12, 2018 · 6 comments
Open

False positive with Symfony Forms #12

aturki opened this issue Sep 12, 2018 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@aturki
Copy link

aturki commented Sep 12, 2018

Hello all,

I get a "Call to an undefined method Symfony\Component\Form\FormInterface::getClickedButton()." error when working with Symfony Forms using the following code (within a Symfony Controller class):

$form = $this->createForm(...); $clickedButton = $form->getClickedButton();

The second line will raise the error since the createForm method returns a FormInterface

@lookyman
Copy link
Collaborator

FIxed in 1b66d8e

@lookyman
Copy link
Collaborator

Actually it wasn't, I completely screwed that up. @aturki can you show me what parameters (especially the first one) are you calling createForm with, your FormType class, and anything else you feel I could need? Thanks.

@lookyman lookyman reopened this Oct 25, 2018
@aturki
Copy link
Author

aturki commented Oct 26, 2018

Hi @lookyman, createForm is called as:
$this->createFormat(DocumentType::class, $entity, $parameters);

Note the DocumentType is a subclass of the Symfony standard Symfony\Component\Form\AbstractType

Let me know if you need extra infos ;)

@lookyman lookyman removed the 0.10.2 label Nov 2, 2018
@lookyman lookyman added the help wanted Extra attention is needed label Nov 30, 2018
@althaus
Copy link

althaus commented Apr 3, 2019

I think it's no false positive, but something ugly in the Form component:

The FormInterface returned by the builder does not include the getClickedButton() method which is part of the Form class. So phpstan would have to inspect the returned form object.

@ThomasLandauer
Copy link
Contributor

I opened a ticket for this at Symfony, see symfony/symfony#35277

@ThomasLandauer
Copy link
Contributor

For now, the solution is to add a PHPDoc - see symfony/symfony#35277 (comment) :

use Symfony\Component\Form\Form;

/** @var Form $form */
$button = $form->getClickedButton();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants