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

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

Open
oleg-andreyev opened this issue Oct 15, 2023 · 1 comment

Comments

@oleg-andreyev
Copy link

❯ 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                         
                                                                                                                                                                                              
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@oleg-andreyev
Copy link
Author

oleg-andreyev commented Oct 15, 2023

just by adding @return

<?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
{
    /**
     * @return FormInterface
     */
    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);
    }
}
                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

but it's getting removed by php-cs-fixer as useless.

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