Scroll down to the script below, click on any sentence (including terminal blocks!) to jump to that spot in the video!Cool, got it! Show me the script!
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.
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.
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!
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:
|... lines 1 - 25|
|class PostType extends AbstractType|
|... lines 28 - 30|
|public function buildForm(FormBuilderInterface $builder, array $options)|
|... lines 33 - 42|
|... 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()|
|... lines 66 - 73|
git diff, I can see that it updated to the new
format. If you have a lot of forms, this is awesome.
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/pathgit clone email@example.com:sensiolabs-de/deprecation-detector.git
Move into the directory and install the composer libraries:
cd deprecation-detectorcomposer 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
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:
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.