What’s New in PhpStorm 2018.2

Experience The Drive to Develop with the second major update for PhpStorm in 2018.

Completion

Custom postfix completion templates

Custom postfix completion templates

Postfix code completion has existed in PhpStorm since version 9, but only provided a limited number of predefined templates. PhpStorm 2018.2 takes postfix completion to the next level by allowing you to add custom postfix completion templates. Create templates to match your project and your personal coding style!

FQCN Completion

FQCN Completion

Completion now matches the namespace in addition to the element name. You don’t have to type or invoke completion for each part of \Illuminate\Auth\Events anymore – just type IAuE instead.

Refactorings

Move Instance Method Refactoring

Move Instance Method Refactoring

PhpStorm already has the Pull Up/Push Down and Make Static/Move Static Method refactorings that help you move methods around. For handling the methods that cannot be made static or moved across the class hierarchy, PhpStorm 2018.2 introduces a refactoring that allows for moving an instance method to a parameter class or to a field class. Simply invoke the Move refactoring on a method declaration, and, if the new refactoring can be applied, you will see a dialog prompting you to choose the target class.

PHP Language

Structural Search and Replace

Structural Search and Replace

In PhpStorm 2018.2, we’ve completely reworked Structural Search and Replace for PHP, which offers lots of new capabilities and greatly simplifies patterns creation. Now you can specify the type of Structural variable, which lets you, for example, find a call to the specific method where the first parameter is a string. You can use a simple pattern to find a foreach loop with an unconditional return statement, or even create your own inspection that will capture an unnecessarily double-quoted string, if your code style enforces this.

Improved SQL Injections

Improved SQL Injections

In version 8, PhpStorm introduced basic support for string concatenations in Language Injections. The dynamic nature of the resulting strings and the strictness of the SQL parser caused a lot of false positive errors in SQL. In PhpStorm 2018.2, we’ve eliminated most such errors and introduced some new features, too. PhpStorm can now substitute the values of constants directly within the injected string, so you can run a query without copy-pasting their values. In addition, we’ve added support for SQL strings that use sprintf parameters.

New Inspections and Quick Fixes

New Inspections and Quick Fixes

PhpStorm 2018.2 delivers handy new inspections such as:

  • Extension is missing in composer.json reports usages of classes/functions/constants from PHP extensions which are not specified in composer.json
  • Non-canonical order of elements in PHPDoc reports tags such as @property, @param, @var, etc. that use a non-canonical order of elements e.g. name Type instead of Type name.
  • Optional parameter before required parameter detects situations when an optional parameter appears before required parameters in a function/method declaration.

Web Technologies Support

New JavaScript Intentions

New JavaScript Intentions

To make you even more productive when working with JavaScript and TypeScript, PhpStorm has a bunch of new intentions that are available when you press Alt-Enter. Here are just some of them: Implement interface, Create derived class, Implement members of an interface or abstract class, Generate cases for switch, and Iterate with for..of.

Completion for events in Vue.js

Completion for events in Vue.js

In Vue templates, PhpStorm now provides code completion for events. Event names are suggested after v-on: or if you use the shorthand notation @event. There’s also code completion for event modifiers.

As usual, all the features and improvements of WebStorm are available in PhpStorm, either out of the box or with free plugins available in the repository. Other noteworthy web-related features include TypeScript 2.9 and 3.0 support, the new Code Coverage feature that helps to find unused code, extract and convert React component refactoring, new integrations with Angular CLI, global file watchers, rerun failed tests and other.

IDE Improvements

TouchBar

Updated UI

We’ve rolled out brand new icons and dark title bars on macOS. Furthermore, PhpStorm 2018.2 brings support for the MacBook Touch Bar! Run and debug your project, commit changes, and update the project right from the Touch Bar.

VCS

VCS

Version control comes with the following changes:

  • Easier resolve of merge conflicts
  • Enhancements in VCS Log tab
  • Browse repository at revision
  • Multiple GitHub accounts
  • Skip the Push dialog

Database Tools

Improvements in Database tools

Database tools in PhpStorm have been improved thanks to our colleagues from the DataGrip team:

  • New SQL formatter
  • Source code migrations
  • Query plan diagram
  • Custom data source

Other improvements:

  • Customizable value for $_SERVER['DOCUMENT_ROOT']
  • Simple CodeSniffer/MessDetector setup
  • The new presentation for Quick Documentation
  • Allow renaming old style constructor to the new style
  • New Add @method tag quick fix for Undefined method
  • Add method quick fix now inserts parameter type hints
  • PHPUnit composite configuration
  • Jump outside closing bracket/quote with Tab
  • HTTP Client: Support environment variables in the request body
  • HTTP Client: Support formatting of POST request body
  • Docker: navigate from compose nodes and containers
  • Docker: wrapping words in Docker logs
Learn about PhpStorm 2018.1

PHP Language

Inline function/method refactoring

Inline function/method refactoring

Using the method’s body in your code can sometimes be more practical than using the method itself, in which case you will need to replace the calls to the method with the actual method’s content. This can be tricky in some cases since you'll need to handle multiple function calls, maintain proper variables' scopes and default values, and reformat the resulting code. The new Inline refactoring will help you with all of the above.

Refactor your code to functional style

Refactor your code to functional style

To help you easily migrate your code between the imperative and functional coding styles, PhpStorm 2018.1 introduces several new inspections and quick fixes. These will convert loops into the array_map, array_filter and array_fill function calls, and vice versa. Only the equivalent transformations are performed, and the logic of your code does not change.

Configurable unchecked exceptions

Configurable unchecked exceptions

PhpStorm 2017.3 introduced a new exception analysis engine that can catch unhandled exceptions, detect missing @throws tags, and so on. To add the sometimes needed configurability, in PhpStorm 2018.1 we’ve added the list of exceptions to be excluded from analysis.

Tests

Creating class from test

Creating class from test

With TDD becoming more and more popular, the situations are pretty common, in which the test is already in place, but the covered class does not exist yet. To handle such situations, PhpStorm 2018.1 will help you generate a class together with the class methods from an existing test. PhpStorm will also take your PSR-0/PSR-4 structure into account to generate the target class and the class methods in their respective locations.

Codeception: code coverage

Codeception: code coverage

We’ve heard your requests for implementing code coverage for Codeception. It’s implemented in PhpStorm 2018.1, and it works exactly like PHPUnit coverage. You will see the coverage results in the Project view as well as in the code editor’s left gutter: the covered code lines will be indicated with the green markers, while the uncovered lines – with red markers.

HTTP Client

Assertions support

Assertions support

Working with responses in the HTTP client has been significantly enhanced, too. PhpStorm 2018.1 brings support for assertions and custom JavaScript (ECMAScript 5.1) code that you can run upon receiving an HTTP response. Since the response is treated as a JavaScript object, you can quickly get access to all its details. You can also create tests that will assert that the request returns what is actually expected. The test results will be displayed on the Test tab, allowing you to navigate to the originating request and re-run a test.

Simplified first start

Simplified first start

PhpStorm 2018.1 will help you jump-start the new HTTP client and migrate from the now-deprecated GUI-based REST client. Live Templates will allow you to quickly insert a request skeleton without much typing; the collection of the most frequently used requests will provide examples useful requests examples. The default HTTP request template is now non-empty and contains some clues for a quicker start, too.

Web Technologies Support

Reformat with Prettier

Reformat with Prettier

With the new Reformat with Prettier action (Alt-Shift-Cmd/Ctrl-P), you can now format the selected code, a file or a whole directory using Prettier. Note that Prettier should be installed as your project dependency or globally on your machine.

Create new Vue project

Create new Vue project

You can now create new Vue projects in WebStorm using Vue CLI. Install it by running npm install --g vue-cli, then press Create New Project – Vue.js on the IDE’s Welcome screen, and answer questions about the template and tools you want to use in your new project.

As usual, all the features and improvements of WebStorm are available in PhpStorm, either out of the box or with free plugins available in the repository. Other noteworthy web-related features include TypeScript 2.7 support and Surround with type guard quick-fix for unresolved properties, Extract Vue component intention, debugging React Native apps, new Node.js Debugger Console and other.

IDE Improvements

Partial commits in Git

Partial commits in Git

With the support for partial Git commits you can now commit only selected changes from the file. Use checkboxes in the diff view of the Commit Changes dialog to select chunks of code you want to commit. You can also add changed lines of code to a new changelist using actions on the editor gutter and then commit the changelist.

Database Tools

Improvements in Database tools

Database tools in PhpStorm have been improved thanks to our colleagues on the JetBrains DataGrip team:

  • Data editor SQL log
  • Now you can tell PhpStorm how to switch schemas: Automatic, Manual, Disabled
  • External schemas in Redshift and virtual schemas in Exasol

Other improvements:

  • Goto Symbol navigation improvements
  • Hierarchy checks for class aliases
  • Gutter icons for running tests
  • New Composer actions
  • Better @covers support
  • New Documentation UI
  • Better HiDPI support on multiple displays for Windows
  • Improved XDebug Profiler viewer
  • Reworked focus subsystem
  • Open Terminal in a specific folder
Learn about PhpStorm 2017.3

Editor-based REST client

New REST client interface

New REST client interface

With the new REST client, all the powers of the PhpStorm code editor are now available for your REST requests. Use code completion to assist you with composing a request, apply refactorings to it, store the request as part of the project and add it to VCS, execute the request, and examine server responses – all without leaving the code editor.

Support for environment variables

Support for environment variables

Define environment variables to hold the values specific for your working environment, for example, the names of your development and production hosts. When composing a REST request, you can substitute its part with a variable to keep a single request suitable for multiple purposes.

Compare your requests

Compare your requests

The diff viewer now handles server responses. If you want to see how your changes affect the response, simply execute a REST request several times. Then, pick a pair of results, invoke the diff viewer right from the code editor, and examine the differences.

PHP Language

Performance Improvements

Performance Improvements

We’ve been working hard on performance improvements in this release. As a result, typing latency in very complex PHP files has decreased significantly. We’ve examined typing latency in the mPDF main file, which is a 38k-line-long mix of PHP, JS, and HTML, and it is down by 75% in PhpStorm 2017.3!

Support of nullability in refactoring

Support for nullability in refactoring

PhpStorm 2017.3 brings nullability support introduced in PHP 7.1, which is now available for the Extract Interface and Change Signature refactorings. It will help you avoid omitting the type declaration, or providing the default null value for the function parameter when you really want to pass or return null. PhpStorm will now preserve nullability when you apply Extract Interface and will no longer signal an error when it detects a nullable type while applying Change Signature.

Improved code templates

Improved code templates

To simplify the creation of classes in namespaced code, the New PHP Class dialog now lets you select a custom PHP file template. Use the ${NAMESPACE} variable in your template and take advantage of namespace completion and PSR-0 / PSR-4 namespace detection as you create the class.
You can also specify the day, year, and month in any PHPDoc template, not just in file templates.

Bring exceptions under control

New Inspection: Unhandled Exception

Unhandled exception

The new Unhandled exception inspection reports exceptions that are neither enclosed in a try-catch block nor documented using a @throws tag. The inspection helps you find all the places in your code where thrown exceptions would lead to a Fatal Error. Accordingly, you can resolve such issues by using quick-fixes like Add @throws tag and Surround with try/catch.

Redundant/Superfluous @throws tag

Redundant @throws tag

Ever forget to update your PHPDoc after refactoring your code? We’ve added the new Redundant @throws tag inspection, and the corresponding Remove @throws tag and Update PHPDoc quick-fixes will now help you clean up your PHPDoc.

Redundant catch clause

Redundant catch clause

The new Redundant catch clause inspection and the corresponding Delete catch clause quick-fix will let you know when the exception you are trying to catch is actually never thrown and therefore your catch block is redundant.

Testing

Create new Codeception test

Create new Codeception and PHPSpec test

The Create New PHP Test dialog adds new templates for the Codeception Unit, Codeception Functional, and PHPSpec test types so you can create new Codeception and PHPSpec tests with more ease.

Test method generation

Test method generation

No more manual creation of test methods! Use the brand new method selector in the Create New PHP Test dialog instead. Simply select all or just a couple of class methods for which you’re going to provide tests, and PhpStorm will generate the test class and the test methods stubs for you. Templates for all supported frameworks are provided to cover your needs for generating project-specific code.

Rerun of PHPUnit test with specific dataset

Rerun of PHPUnit test with specific dataset

In PhpStorm 2017.3, you can rerun a failed PHPUnit test with specific dataset. If you have a test method that uses the data provider and only one of the data sets fails, you don’t have to re-run the entire test anymore. Simply choose a specific data set from the previous test run and Run/Debug it again.

Undefined PHPUnit data provider

Undefined PHPUnit data provider

PhpStorm 2017.3 introduces the Undefined PHPUnit data provider inspection, which indicates a @dataProvider method that’s not found in unit tests. You can then easily create the missing method by applying the suggested Create data provider quick-fix.

Twig support

Injections in Twig templates

Injections in Twig templates

We’ve implemented language injections for Twig custom tags and named blocks. You can inject a language into the named block or between custom tags. You can also create permanent injection rules.

Improved Twig formatting

Improved Twig formatting

PhpStorm 2017.3 brings improved Twig formatting that can now handle complex structures and provide correct indentation for them.

Web Technologies Support

Improvements in Vue.js support

Improvements in Vue.js support

This update brings lots of improvements to PhpStorm’s support for Vue.js! Code completion and navigation to the definition now work for Vue props, properties in the data object, computed properties, and methods. Closing curly braces are now added automatically in Vue templates. We've also added a collection of code snippets for Vue. These code templates can help you save time typing some frequently used blocks of code. With a new Vue file template, you can also create new components faster.

Better code completion and documentation for JavaScript

Better code completion and documentation for JavaScript

Code completion and parameter info for the standard JavaScript objects and methods and Web APIs has improved, as these features are now powered by the TypeScript declaration files. The documentation available via F1 now also includes a brief description for methods, which either comes from the bundled definition files or is fetched from MDN.

New Pull Member Up refactoring

New Pull Member Up refactoring

With the new refactoring you can now move class methods up the class hierarchy – from your current JavaScript or TypeScript class to its parent class or interface. Or if there’s no parent class yet, you can extract fields and methods to a superclass using the new Extract superclass refactoring.

As usual, all the features and improvements of WebStorm are available in PhpStorm, either out of the box or with free plugins available in the repository. Other noteworthy web-related features include Extract type alias and Extract interface refactorings in TypeScript, multiple JavaScript versions in a project, improved Jest integration, better support for CSS, Import code style from ESLint and TSLint and other.

Version Control

Version Control

Version control comes with the following changes:

  • Switch between branches preserves your workspace
  • Changelists can now be renamed in the Shelf tab
  • D'n'D between Shelf and Local Changes tabs

Database Tools

Improvements in Database tools

Database tools in PhpStorm have been improved thanks to our colleagues on the JetBrains DataGrip team:

  • Improved Database view
  • SQL generator
  • JOIN statement completion
  • SSH tunneling

Other improvements:

  • Redesigned Code Style|PHP settings page
  • New Composer Log
  • Improved PHPUnit Run configuration
  • Define visibility for initialize fields intention
Learn about PhpStorm 2017.2