Login to bookmark this video
Buy Access to Course
04.

Deprecation Fixing Tools

Share this awesome video!

|

Keep on Learning!

Tip

The video for this tutorial will be ready very soon!

Ideally, your outside bundles are no longer triggering deprecated warnings. Now it's time to update our code for Symfony 3. This means finding deprecation warnings, fixing them everywhere you can think of, and, well, repeating! It's pretty simple, but sometimes the true source of a deprecation can be tricky to find.

Symfony Upgrade Fixer

Fortunately, there are 2 tools to help us. Google for Symfony Upgrade Fixer. This is a sweet tool made by my good friend Saša. It tries to find deprecated code and fix it for you. How nice!? It only supports a few things, but it aims to fix the most annoying ones, like form changes.

Copy the wget line and paste it into your command line. Or just use that URL to download the file manually. Copy the second permissions line to make that file executable. Cool! Now we have a symfony-upgrade-fixer utility! Run it!

symfony-upgrade-fixer

And then actually use it with fix and then . to fix this directory:

symfony-upgrade-fixer fix .

Behind the scenes, that's snooping through your project and writing new code for you. Ding! It fixed two form classes:

80 lines | src/AppBundle/Form/PostType.php
// ... lines 1 - 25
class PostType extends AbstractType
{
// ... lines 28 - 30
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ... lines 33 - 42
$builder
// ... lines 44 - 47
->add('summary', TextareaType::class, array('label' => 'label.summary'))
->add('content', TextareaType::class, array(
// ... lines 50 - 51
))
->add('authorEmail', EmailType::class, array('label' => 'label.author_email'))
// ... lines 54 - 55
))
;
}
// ... lines 59 - 78
}

// ... lines 1 - 27
class DateTimePickerType extends AbstractType
{
// ... lines 30 - 61
public function getParent()
{
return DateTimeType::class;
}
// ... lines 66 - 73
}

By using git diff, I can see that it updated to the new TextareaType::class format. If you have a lot of forms, this is awesome.

Symfony Deprecation Detector

This tool caught a few things, but there's a lot more. So... let's try another tool! Google for Symfony Deprecation Detector. This tool doesn't fix your project, but it detects more things than the first one.

Copy the clone command and run it in the terminal:

cd any/path
git clone git@github.com:sensiolabs-de/deprecation-detector.git

Move into the directory and install the composer libraries:

cd deprecation-detector
composer install

This will give us a new binary that we can use on our project. Switch back into the directory of our project, then run the bin/deprecation-detector command from that project:

/path/to/deprecation-detector/bin/deprecation-detector

Boom! This correctly sees that 3 form types still have a getName() method, which they should not have anymore. Go into AppBundle/Form, open up each form type, and remove the getName() method from the bottom.

Perfect! Try the command again:

/path/to/deprecation-detector/bin/deprecation-detector

No violations! I wish this meant that you had no more deprecated features, but it's an imperfect tool. We need to hunt for the last few deprecations.