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
Starting from PhpStorm 2019.1, Code Cleanup comes with PHP-specific intentions. We’ve added following cleanups in this release:
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.
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.
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:
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.
Also, now when you run the Add field intention, PhpStorm will generate a PHPDoc for it too:
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.
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.
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
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!
Your JetBrains PhpStorm Team
The Drive to Develop