umpirsky / Symfony-Upgrade-Fixer

Analyzes your Symfony project and tries to make it compatible with the new version of Symfony framework.
MIT License
275 stars 18 forks source link

Replace constructor of form types with options #28

Closed althaus closed 8 years ago

althaus commented 8 years ago

Hey,

I don't know if it's possible, but I'd be awesome, if the fixer could move constructor parameters to the options resolver:

Before:

$someVar = new SomeVar('acme');
$form = $this->createForm(new MyType($someVar), $entity);

After:

$form = $this->createForm(MyType::class. $entity, ['someVar' => $someVar]);

And in MyType:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setRequired(['someVar']);
    $resolver->setAllowedType('someVar', '\App\Bundle\SomeVar'); 
}

I'd be happy if the base change could be automated, but I guess the invokation in controllers or similar would be too hard.

Cheers Matthias

umpirsky commented 8 years ago

@althaus I'm afraid it is both too hard and out of scope of this project.

But I agree it would be a cool thing to have.

Anyone is free to use this repo as a base, but I think this does not belong to upgrade fixer, maybe a dedicated tool for such things can be a good idea.

Thanks.

althaus commented 8 years ago

@umpirsky Okay... your fixer is still a handy tool! :+1: