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

Open
#377 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php, symfony
Domain
devtools

Research direction

Start with the provided UploadFileType.php example and reproduce the failure using vendor/bin/phpstan analyze src/Form/UploadFileType.php. Trace how the Symfony form extension handles FormBuilderInterface and TData after the listed PHPStan upgrades; done means the example analyzes without the invalid Symfony\Component\Form\TData error.

Written by the indexing model from the issue text.

Description

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                                                                               
Dominant language
PHP
Stars
800
Forks
104
Avg merge
4m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-symfony

All issues in phpstan/phpstan-symfony

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.