Skip to content

Template type TData on class Symfony\Component\Form\FormInterface is not covariant #363

Open
@oleg-andreyev

Description

@oleg-andreyev
❯ composer bin phpstan info phpstan/phpstan-symfony
[bamarni-bin] Checking namespace vendor-bin/phpstanser bin phpstan info phpstan/phpstan-symfony                                                                                                          1 ✘  14:44:46  
name     : phpstan/phpstan-symfony
descrip. : Symfony Framework extensions and rules for PHPStan
keywords : 
versions : * 1.3.4
type     : phpstan-extension
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : 
source   : [git] https://github.com/phpstan/phpstan-symfony.git 383855999db6a7d65d0bf580ce2762e17188c2a5
dist     : [zip] https://api.github.com/repos/phpstan/phpstan-symfony/zipball/383855999db6a7d65d0bf580ce2762e17188c2a5 383855999db6a7d65d0bf580ce2762e17188c2a5
path     : /Users/oandreyev/Development/competitors/vendor-bin/phpstan/vendor/phpstan/phpstan-symfony
names    : phpstan/phpstan-symfony

Simple override

<?php

declare(strict_types=1);

namespace App\Symfony\Component\Form;

use EasyCorp\Bundle\EasyAdminBundle\Form\Type\FiltersFormType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormFactory as OriginalFormFactory;
use Symfony\Component\Form\FormInterface;

class FormFactory extends OriginalFormFactory
{
    public function createNamed(string $name, string $type = FormType::class, mixed $data = null, array $options = []): FormInterface
    {
        if ($name === 'filters' && $type === FiltersFormType::class) {
            $options = array_merge($options, [
                'validation_groups' => ['admin_filter'],
            ]);
        }

        return parent::createNamed($name, $type, $data, $options);
    }
}
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/Symfony/Component/Form/FormFactory.php                                                                                                                                           
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  22     Method App\Symfony\Component\Form\FormFactory::createNamed() should return Symfony\Component\Form\FormInterface<TData>|Symfony\Component\Form\FormInterface<TData|null> but returns  
         Symfony\Component\Form\FormInterface<null>|Symfony\Component\Form\FormInterface<TData of mixed>.                                                                                     
         💡 Template type TData on class Symfony\Component\Form\FormInterface is not covariant. Learn more: https://phpstan.org/blog/whats-up-with-template-covariant                         
         💡 Template type TData on class Symfony\Component\Form\FormInterface is not covariant. Learn more: https://phpstan.org/blog/whats-up-with-template-covariant                         
         💡 Template type TData on class Symfony\Component\Form\FormInterface is not covariant. Learn more: https://phpstan.org/blog/whats-up-with-template-covariant                         
                                                                                                                                                                                              
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions