Develop faster Symfony applications using PhpStorm

symfony phpstorm plugins
Written by Charaf JRA

If you are a developer, then you will definitely know what an IDE is and how it helps to code easier and faster.

For PHP developers, the best IDE available in the market is PhpStorm, a product from JetBrains that is similar to IntelliJ IDEA for Java&JavaEE, it offers a Fast and Safe Refactoring, a Smart Code Navigation, an Intelligent Coding Assistance and an Easy Debugging and Testing.

If you use Symfony PHP Framework, then I recommend you to use Phpstorm because it has a lot of plugins, live templates and tricks (described below) that will make your life easier and will help you to generate your repetitive code snippets quickly.

This article admits that you know how to manage plugins in PhpStorm, if you don’t then check this documentation.

Symfony Plugin:

A great  PhpStorm plugin for Symfony2 and Symfony3 users, it is installed one time but must be enabled and configured in each Symfony project you use.
It provides advanced IDE features for Symfony-specific navigation, code completion, Quick-fixes, support for Twig templates, service container, Doctrine, translations, Symfony routes, Symfony forms, Symfony  events, Symfony command line tool, code style, and much more.
This plugin becomes very popular in PHPStorm repository with more than 1,4M downloads.

Services Example:

services_symfony_phpstorm_plugin

Twig Example:

twig_quick_navigation_symfony_phpstorm_plugin

More examples and details in the Official page

PHP Annotations Plugin:

This plugin offers a lot of features, especially code completion, and quick-fixes.All the available features until now:

  • Attach PhpClass to their DocTag to support “Code > Optimize Imports”
  • Auto alias detection on use statement
  • Filter annotation classes on targets like method, class, property, …
  • Goto for doc tags and property names
  • Detect annotation property values on phpclass property name including types
  • Index classes with @Annotation inside doc block
  • Plugin extension point
  • Doctrine related providers
  • Class import annotator
  • Class constants in DocTags
  • Doctrine ORM intention and quick fixes for repository and properties

More examples and details in the official page

 PhpStorm Live templates for Symfony:

symfony_phpstorm_live_templates

Live templates for Symfony 2 and Symfony 3 are a list of shortcuts to help you write code snippets quickly.

The starting list includes:

  • action (inside a controller): Builds an action method (GIF Above)
  • 404Unless (controller): Adds an if statement with a 404
  • formhandle (controller): Adds form-handling boiler-plate code
  • formrow (twig): Renders form_row(form.???)
  • formrowfull (twig): Renders the widget, label and errors for a field
  • include (twig): Adds {{ include('???') }}
  • method (controller): Adds @Method annotation
  • path (twig): Adds {{ path('???') }}
  • render (twig): Adds {{ render(controller('???')) }}
  • rendertwig (controller) Adds $this->render('???')
  • repofind (controller) Adds $this->getDoctrine()->getRepository('??')->??()
  • route (controller) Adds @Route annotation
  • service (yaml) Adds the basic YAML service definition structure
  • tags (yaml) Adds a tags line to a service

Emmet( Zen-Coding):

This plugin is installed and enabled by default once you install PhpStorm,it is available in a lot of text editors and IDEs, not only PhpStorm.

It’s an abbreviation engine that has a modular structure which allows you to expand abbreviations into different languages. Emmet currently supports CSS, HTML, XML/XSL.

Example:

This line:

div#page>div.logo+ul#navigation>li*5>a

Can be expanded into:

<div id="page">
        <div class="logo"></div>
        <ul id="navigation">
                <li><a href=""></a></li>
                <li><a href=""></a></li>
                <li><a href=""></a></li>
                <li><a href=""></a></li>
                <li><a href=""></a></li>
        </ul>
</div>

Emmet documentation

Have other tools to boost your productivity, share them with us in the comment section below.

About the author

Charaf JRA

I'm a Code enthusiast , Blogger, Geek and Software Engineer. I created this blog to share my inspirations and my new experiences.If you like to contact me , use the contact form above or follow me on twitter

%d bloggers like this: