Every PhpStorm release comes with new and enhanced refactorings, saving you from having to perform tedious manual tasks and making it easier for you to maintain your code.
PhpStorm 2018.3 is no exception. In this release, we are introducing the Replace with Alias, Inline Alias, and Сhange Class Member Visibility refactorings, as well as some tweaks to enhance some of our existing refactorings.
Let’s take a look at them in more detail.
Replace with Alias refactoring
With the new Replace with Alias refactoring, you can replace the import class statements such as
use Foo\Bar with ones referring to a class alias, for example,
use Foo\Bar as Baz. The refactoring will also replace all
Bar usages with
You can apply this refactoring from a class usage, too.
In PhpStorm 2018.3, aliases are displayed in italics both in unqualified and fully qualified class names, so it has become much easier to distinguish them from regular classes. If necessary, you can customize their appearance under Settings / Preferences | Editor | Color Scheme | PHP:
Inline Alias refactoring
The Inline Alias refactoring is opposite to the above one: it lets you inline a redundant alias and update the corresponding usages accordingly.
Just like replacing with an alias, the refactoring works in both use statements and occurrences.
Сhange Class Member Visibility refactoring
The new Сhange Class Member Visibility refactoring lets you change the visibility of a class member, be it a property or a method. PhpStorm will analyze the class member usages and make sure that the visibility change does not introduce any bugs.
If there are any issues found, PhpStorm will display the conflicts in the Find tool window and prompt you to take an action.
Rename refactoring for private fields
In earlier versions of PhpStorm, when you renamed the private properties of a class using the Rename refactoring, it would search through the entire project, which was not optimal performance-wise. PhpStorm 2018.3 will, by default, search through context usages, and so performance is much better for this refactoring.
In some cases, searching through the entire project is still required. For example, if you use a
property_exists() or similar function, you can access the private class property from outside the scope. To handle this, simply enable the new Search in global scope option in the Rename dialog when performing a refactoring. The usages will be detected so that you can rename them, too.
Extract method refactoring
The Extract method refactoring has been given a useful enhancement. In PhpStorm 2018.3, it will now properly infer the parameters’ data types based on the type of the source variables.
Let us know what you think, and stay tuned for more updates!
Your JetBrains PhpStorm Team
The Drive to Develop