PhpStorm 2019.1: Debug Twig and Blade templates, search for dead code, improved auto-completion and much more



    Hello, Habr!

    We are glad to present the first major release of PhpStorm this year!
    An overview of the release can be found on the “What's new” page . And under the cut, a translation of this page with a demonstration of the most interesting new features.

    You can download the new version on the website or using the Toolbox App . As always, a 30-day trial is available. The full version can be used by holders of an active subscription to PhpStorm or All Products Pack, and free of charge - by students and developers of open source projects.

    In total, 1118 bugs were fixed in the release and many new features were added. Here are the most interesting ones.

    Debugging Twig and Blade Templates


    Thanks to the debugger, you can quickly deal with the most catchy bug, but here to find problems in the templates, you have to wade through the jungle of machine-generated code. In PhpStorm 2019.1 we added the ability to debug the original uncompiled .twig and .blade.php template files .

    To do this, just specify the path to the compiled templates (cache) in the IDE settings: Languages ​​& Frameworks | Php | Debug | Templates for Twig or Blade .

    In the case of Twig also need to specify the options debugand auto_reloadconfigurations.
    And for Blade, everything will work automatically, but only starting with Laravel 5.8.

    After that, you can turn on the debugger and set a breakpoint directly in the template. The execution will stop at the specified location, and all the usual debugging options will be available: step-by-step execution, local and global variables, value tracking (watch) and everything else.



    Speaking of debugging: we actively support the author of Xdebug Derick Rethans to improve the debugger, solve accumulated problems and expand the possibilities of its use in PhpStorm.

    Dead Code Detection


    PHP marks 24 years this year and it is not surprising that you often come across legacy code. The first thing you want to do is to clean and remove the excess. The new inspection of the Unused declaration will just help in this matter.
    PhpStorm 2019.1 can analyze your code on the fly and highlight directly in the editor those classes, class members and functions that are probably not used anywhere.



    You can also find all unused items in batch mode. To do this, call the Code -> Run Inspection by Name menu and select the Unused Declaration inspection . You will receive a report with a list of all problems with a description and quick fixes.



    New refactoring and quick action


    By tradition, we have added several new refactorings to make routine actions quick and error-free.

    Manipulating strings
    If you press Alt + Enter on any string expression, you will see a whole list of available conversions. For example, there is already a conversion from / to NOWDOC / HEREDOC, replacement of quotes, splitting a string into two with concatenation.
    And in this release, we added some more convenient things - copying the concatenated string to the buffer, replacing the string concatenation with interpolation or calling the sprintf () function and, accordingly, the reverse actions:



    Deleting unused variables
    A new inspection will detect and allow you to delete an unused variable in assignment operations and constructions usein closures.



    Refactoring Move to Class
    With this refactoring, you can safely move functions from PHP files to classes. PhpStorm will update all calls to these functions.



    When restoring order, you may need to move several functions at once - this is also supported by PhpStorm. You need to select the desired functions in the Structure window and then call the Move to Class refactoring.

    Inspection Method May Be 'static'
    This inspection will detect methods that can be converted to static, that is, those that do not use an instance of the class. Such methods will have a contextual action available - you can press Alt-Enter and select “Make static”. As expected, all calls will be fixed automatically.



    Improved auto-completion mechanisms


    Using the .phpstorm.meta.php file, you can tell the IDE which arguments are expected in the function or what values ​​it can return. PhpStorm will use this information for auto-completion.
    Let's say a function expects some kind of constant as an argument. Formally, the type of this constant is permissible, integerbut in reality we know the set of possible constants.
    For example, json_encode($data, /* вот тут битовая маска из констант JSON_* */)
    We may also have a function that returns a constant, for example json_last_error().
    In PhpStorm 2019.1, auto-completion for these and many other built-in functions already works out of the box:



    Moreover, such auto-completion can be done in any project / library / framework by simply adding a special .phpstorm.meta.php file to the project. And there can be many such files, PhpStorm will find and combine them.
    For example, such files already exist for Symfony in the form of the King2500 / symfony-phpstorm-meta package - it comes with the Symfony plugin .
    Read more in the post about new features .phpstorm.meta.php .

    Import Optimization


    The system of analysis and correction of imports was slightly reworked. PhpStorm will now, if possible, propose replacing the full name of the class with import or removing it altogether if it is redundant.
    Also added the ability to sort expressions usealphabetically or by length.

    Code Cleanup Code Cleanup Tool


    This tool enables secure batch conversions. For example, in the whole project right away, in a certain directory, etc.
    In PhpStorm, it was available for a long time, but only in 2019.1 did it add features for PHP. First of all, it supports two coding style correction tools: PHP CS Fixer and phpcbf from PHP_CodeSniffer. As well as two inspections to optimize imports from the previous paragraph.



    This tool can be launched at any time manually or before committing, simply by checking the corresponding dialog in the commit dialog:



    Reusing Docker Containers


    Added support for launching Docker containers in docker-compose run and docker-compose exec modes. The first mode is suitable for lightweight containers that stop immediately after starting. The second allows you to reuse running containers without having to restart.



    Among other improvements:

    • Flexible PHPDoc settings: you can customize the order of elements and indents in Preferences | Editor | Code Style | PHP tab PHPDoc;
    • The default PHP file template is cleared - no more Created by PhpStorm;
    • New quick action to add a class property to the constructor;
    • You can enable strict mode globally,
      even if there is no directive in the filesdeclare(strict_types = 1);


    Vcs


    The version control system has made many useful improvements:
    • Fixup and Squash actions added to Git log;
    • When viewing diffs, you can now swap panels;
    • Push with force is now safer because the flag is used --force-with-lease;
    • The Uncheck all option for partial commits has been added to the commit dialog - with it you can turn off all changes and then select only the necessary ones:



    IDE Enhancements


    Recent Locations Dialog
    Most of the time when working on a task, developers have to read code, not write. Therefore, fast navigation between files is always very relevant. PhpStorm already had a Search Everywhere popup ( Shift-Shift ) , Bookmarks and Favorites ( Cmd + 2 / Alt + 2 ), moving the story back and forth ( Cmd + [ - Cmd +] / Ctrl + Alt + Left - Ctrl + Alt + Right ), or view the latest files ( Cmd + E / Ctrl + E ) .
    In PhpStorm 2019.1, we added another interesting feature - the Recent Locations dialog ( Cmd-Shift-E / Ctrl + Shift + E), which will show the last pieces of code that you viewed or edited. This can come in handy if you want to quickly move through the history and see the context in order to understand exactly where to move.



    New Interface Themes
    PhpStorm comes with three themes: Light, Darcula, and High Contrast. If you want to try something fresh, then install one of the new themes: Dark Purple , Gray or Light Cyan . Also now you can create themes yourself, while it is possible to set the color of any element or icon. Read more in the documentation .



    Soft-wraps depending on file type
    If you often work with markdown or text files, now line wrapping for them will be turned on automatically. You can also specify other file types in the Preferences | Editor | General | Soft-wrap files.

    PhpStorm, as always, includes all updates from WebStorm :
    Documentation of CSS properties, HTML tags and browser support is now taken from MDN and contains links to related articles, TypeScript support in Vue applications has improved, 17 new inspections for Angular applications have been added, and JavaScript and Node.js debugger panels have new interactive consoles.

    ... and from DataGrip :
    Now additionally supported Greenplum, Vertica, Apache Hive; Now you can select the default project folder; as well as improved means of completing structures and attributes.

    This is all that we managed to talk about - but not all that was included in the release. A complete list of changes, as always, can be found in the very large release notes .

    Thanks for attention!
    JetBrains PhpStorm Team

    Also popular now: