PhpStorm 2019.1 EAP #3

PhpStorm 2019.1 EAP build 191.5109.15 is now available!
This build delivers code cleanup for PHP, ability to define the order of tags in PHPDoc, improvements for Introduce Constant and Extract Method refactorings, and even more!

You can download it on the website or via JetBrains Toolbox App. Or, if you have the previous PhpStorm 2019.1 EAP build (191.4738.10) installed, you should soon get a notification in the IDE about a patch update.

Code Cleanup for PHP

In PhpStorm, Code Cleanup is a batch action that lets you run a number of safe transformations on the whole project or a part of it. In PhpStorm 2018.3 and earlier, this tool included only JavaScript inspections inherited from WebStorm as all of its features are bundled in PhpStorm.

Starting from PhpStorm 2019.1, Code Cleanup comes with PHP-specific intentions. We’ve added following cleanups in this release:
code-cleanup-inspections

Code Style
Here we have two inspections that can fix a redundant usage of fully qualified class names. PhpStorm can replace them by either adding a corresponding ‘use’ statement or just removing the extra namespace part.
code-cleanup-fqcn

Quality Tools
This one includes support for two popular fixers for PHP_CodeSniffer rules: PHP CS Fixer and phpcbf. You can now run any of those to fix code style automatically.

You may run all or selected cleanups at any time by calling Code->Code Cleanup… from the menu.

What’s even cooler about Code Cleanup is that you may run it automatically before committing to VCS! This will run fixes on all files selected for commit.
code-cleanup-before-commit

Define order in PHPDoc

PhpStorm is able to automatically generate PHPDoc comments based on your code. You may configure how you want the comments to look, by going to Preferences | Editor | Code Style | PHP and opening the PHPDoc tab. For example, it’s very handy to add some aligning to improve the visual perception of a doc block:
phpdoc-align

In PhpStorm 2019.1, you can configure the order of generated fields. Select the field and move it up/down with arrow buttons to define the lineup. Or add a tag if it’s not in the list yet.
phpdoc-tags-order

Also, now when you run the Add field intention, PhpStorm will generate a PHPDoc for it too:
quick-fix-add-field

Introduce Constant Refactoring Improved

Sometimes you may find the usage of magic numbers or, broadly, any magic values in your code. This is a potential source of bugs in the application so you may want to quickly move values to constants. You can do that by running the corresponding refactoring called Extract Constant. Put the caret over the value, and press Cmd+Alt+C (Ctrl+Alt+C on Win/Linux). Now you’ll be able to not only introduce a constant but also add it to another class which it matches better.
refactoring-extract-constant

Usability Improvements for Extract Method

Another handy refactoring available in PhpStorm is Extract Method. It can be used to easily move some piece of code to a separate method.

Let’s say you have a fat controller or service and you want to start refactoring it. Select a few lines of code that implement some related logic and then click Cmd+Alt+M (Ctrl+Alt+M on Win/Linux). Next, you’ll see a popup with a preview and some options that will help you create a new method out of those lines. PhpStorm will suggest a name and ask you if you would like to change it. If the selected piece of code contains variables of outer scope, these will be added as parameters of a new method.

Note that it’s much better to perform this kind of refactoring with PhpStorm – instead of doing manually – because PhpStorm will track variables, names, and other things for you and thus ensure that the changes are done safely.
refactoring-extract-method

Discover other cool refactorings by pressing Ctrl+T (Shift+Ctrl+Alt+T) at any place in your code.

Other notable changes for PHP

  • Auto-detect Phing with Composer
  • Ability to move multiple functions and constants at once
  • Import reference on paste: ask to reuse existing alias
  • Place the cursor on a class name when opening a file if the file contains only one class
  • Fixed: Exception with copy & paste on debug watches window

See all the PHP-related bug-fixes and improvements in our issue tracker or the full list of changes in the release notes.

Please report any problems to our issue tracker, or add comments to this post. Your feedback is much appreciated. And the most active EAPers will get prizes from us!


Download PhpStorm 2019.1 EAP build 191.5109.15 for your platform from the project EAP page or click “Update” in your JetBrains Toolbox App.

Your JetBrains PhpStorm Team
The Drive to Develop

This entry was posted in Early Access Program and tagged , , , , . Bookmark the permalink.
  • Michael Bladowski

    the global search is broken now :-(

    • Eugene Morozov

      It is. Sorry!
      Will be fixed in the next build: https://youtrack.jetbrains.com/issue/WI-45283

      • Fabio Chelly

        Can’t it be fixed sooner in a simple fixed temp build? Ths whole EAP version is completely useless like it is.

        • Dmitry Tronin

          I’ll check that with a team

          • https://twitter.com/michabbb Michael Bladowski

            @dmitry_tronin:disqus is there any ETA for this fix ? thanks !

          • Ali Alwash

            Almost every Wednesday there is a new EAP :)
            Guess what, today is Wednesday and a new EAP is released!

          • Dmitry Tronin

            Sorry for missing a question. The fix is available with today’s EAP build

  • Fabio Chelly

    Search inside PHP files is completely broken

  • joelharkes

    Yea ive noticed too: updates are not always every stable lately and the lack of proper new features is sad..

    I feel like half these features described above are already in 2018, other half I wouldnt use (line wrapping is terrible) or could already be done easily with an external tool.

    All things describes here are just minor feature.

    When is there gonna be phdoc generic (template) support? Or at least warnings when you triple equals wrong types (at least I haven’t spotted these yet?)

    • http://pronskiy.com Roman Pronskiy

      Thanks for the feedback!
      This is an early access version of the product. EAP versions may not be reliable, may not work as intended and may contain errors. Any use of the EAP product is at your own risk.

      Also, note that this is already a third EAP build, so we are slowly moving to the stabilization phase, and add less prominent features.

      As for PHPDoc generic support – right now there is no standard for this. PSR-5 draft does not describe it either. We are carefully looking into what PHP community is adopting and will add full support for it as soon as it makes sense. So far there is a parser level support for collection type hints.

      Warnings when you triple equals wrong types – thanks for the idea! https://youtrack.jetbrains.com/issue/WI-45293 please feel free to vote for the issue to receive updates on progress.

      • Vasily

        What constitutes community in your case? Because what we’ve learnt from the PSR-7 / Symfony fiasco is that there’s no such thing.

        Both psalm and phan support these annotations, why can’t PHPStorm take a lead here, formalise the syntax, publish it as a separate PSR and be done with it?

    • sabat24

      Yea ive noticed too: updates are not always every stable lately and the lack of proper new features is sad..

      I agree that there is problem with stability of updates. And I think of stable versions not EAP ones. Latest stable update broke some core and minor functionality in VCS and task management. In my opinions lack of new features is perfectly fine as long as already provided features works very well with enough options to use them. Unfortunatelly in my case for example I can’t use VCS becase there are a lot of minor bugs or there are not enough options to use it correctly so I have to use external tool and I get no benefits of VCS almost at all. New features are great but what is more important, the old one shouldn’t be broken after new release and shouldn’t be they should not be abandoned (I sometimes find issues created many years ago with many votes) not fully completed moving all efforts to new features.

  • Mohamad Norouzi

    no JBR 11 for phpstorm yet :(

  • Федя Федя

    Place the cursor on a class name when opening a file if the file contains only one class

    How to disable it? Kills my workflow

    • Eugene Morozov

      Actually, it would’ve been convenient if it worked as it’s designed to :)
      Here’s the bug that makes it kill your workflow, we expect the fix to get released next week: https://youtrack.jetbrains.com/issue/WI-46109