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

Form "has invalid type Symfony\Component\Form\TData" after patch upgrade #377

Open
Jean85 opened this issue Jan 23, 2024 · 0 comments
Open

Comments

@Jean85
Copy link

Jean85 commented Jan 23, 2024

I'm getting the same that arose in #337 after merge during a PHPStan patch upgrade with Renovate:

Package Type Update Change
phpstan/phpstan require-dev patch 1.10.55 -> 1.10.56
phpstan/phpstan-symfony require-dev patch 1.3.6 -> 1.3.7

Before I used @template-extends AbstractType<void>, now it fails every time, with or without the annotation.

Code example:

<?php

declare(strict_types=1);

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\File;

/**
 * @template-extends AbstractType<mixed>
 */
class UploadFileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add(
            'file',
            FileType::class,
            [
                'label' => 'Zip',
                'required' => true,
                'constraints' => [
                    new File([
                        'mimeTypes' => [
                            'application/zip',
                        ],
                        'mimeTypesMessage' => 'Please upload a valid zip file',
                    ]),
                ],
            ]
        );

        $builder->add('submit', SubmitType::class, ['attr' => ['class' => 'btn-primary'], 'label' => 'Save']);
        $builder->setMethod(Request::METHOD_POST);

        parent::buildForm($builder, $options);
    }
}

Error:

$ vendor/bin/phpstan analyze src/Form/UploadFileType.php 
Note: Using configuration file /var/www/***/***/phpstan.neon.
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ------------------------------------------------------------------------------------------ 
  Line   UploadFileType.php                                                                        
 ------ ------------------------------------------------------------------------------------------ 
  19     Parameter $builder of method AppBundle\Form\UploadFileType::buildForm() has invalid type  
         Symfony\Component\Form\TData.                                                             
 ------ ------------------------------------------------------------------------------------------ 


                                                                                                     
 [ERROR] Found 1 error                                                                               
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

No branches or pull requests

1 participant