PhpStorm 2020.2

PHP 8のunion型をサポート
8月 03, 2020 - 13:00


PHP 8 Union Types

  • Convert PHPDoc to native union types - Union types used to be provided via PHPDoc, and now PhpStorm highlights such occurrences.
  • Switch Language Level to PHP 8 - To enable the PHP 8 related features, switch the language level to PHP 8 in any of the following ways:
    • Use the Alt+Enter quick-fix directly in the code editor.
    • Go to Preferences | Languages & Frameworks | PHP and use the PHP language level list.
    • Specify the PHP version requirement in composer.json, and PhpStorm will pick it up automatically.
  • Perform type validation - PhpStorm analyzes calls, calculates possible types, and highlights problem areas relating to union types. The checks work on all levels: properties, arguments, and return values. In complex code bases, it helps you see the problems at first glance. PhpStorm will highlight places that require attention even before the code is run.
  • Detect duplicate and redundant types - There are many type combinations that are forbidden or redundant. For example:
    • bool|false
    • Foo|Foo
    • object|User
    • iterable|array or iterable|Traversable
  • Work with nullable types - When there is a single nullable type, it is allowed to use either ?Type notation or Type|null in PHP 8. But when there are multiple types combined with null, using ?Type1|Type2 is forbidden as ambiguous. PhpStorm highlights these violations and provides an Alt+Enter quick-fix to convert them.
  • Follow variance rules - During inheritance, PHP allows you to modify types if you follow these basic rules:
    • Parameter types are contravariant, i.e. can be extended.
    • Return types are covariant, i.e. can only be narrowed down.
    • Property types have to evaluate to the same type.
  • Use pseudotype false - In PHP 8 there will be a special false pseudotype that can be used only in union type declarations. It is widely used in the standard library, see strpos() or array_search(), for example, and can be applied elsewhere to indicate a negative result. PhpStorm highlights incorrect usages and takes type inference into account.
  • Remove redundant PHPDoc - After adding a native union type declaration, a PHPDoc may become unnecessary because it does not provide any extra information. You can now remove it with a quick-fix Alt+Enter.

New Control Flow Engine

  • Condition always true - PhpStorm can now analyze complex code paths and detect if the condition in an if-else block makes sense or is redundant.
  • Result of ‘instanceof’ is always true - Similar to conditions, PhpStorm is able to detect when instanceof checks are appropriate, or if they always evaluate to true because of the inferred type in the type hierarchy.
  • New action: Type Info - The new action lets you see the inferred type of any selected expression.
  • Expression is always ‘null’ - PhpStorm can detect when the variable is guaranteed to be null only. In this case, the IDE suggests simplifying the expression to make it clearer.

Quality Tools Improvements

  • It is now possible to run quality tools via Docker Compose. To do this, go to Preferences/Settings | Languages & Frameworks | PHP, and add a new remote interpreter based on Docker Compose. Reformat action for PHP-CS-Fixer and PHPCBF can now be run through a remote interpreter too. If PHP_CodeSniffer’s ruleset.xml has an "exclude-pattern" section, PhpStorm will now take this into account and not analyze files under the specified path.

Composer Improvements

  • Support for custom Satis/Packagist packages - If there are custom sources specified in the “repositories” section, you will get completion for custom packages. There is now a gutter icon showing the current state of the caching of custom repositories.
  • Completion for multiple versions - When a package has multiple versions separated with a comma or pipes (||), PhpStorm provides completion with all available versions for this package. It used to be that completion was lost after typing ~, ^, or >=, but now it works as expected with any of these range constraints in composer.json.
  • Quick access to settings of tools added as dependencies - PhpStorm provides many integrations with third-party tools. Now, if a supported tool is declared in composer.json, there will be a wrench icon in the gutter beside it. You can click it to go straight to the corresponding section of preferences.
  • Extract Class Refactoring - If a class gets cluttered and burdened with a lot of additional responsibilities, it is now possible to refactor it by moving methods and properties to a new class with the Extract Class refactoring. Select a function, a method, or a property you’d like to move and press Ctrl+T and select Extract class. The refactoring will create a new file, instantiate an object of the class in the constructor, and adjust the usages automatically.
  • Command Line Tools Improvements - Support for remote interpreters is now available for PHP Command Line Tools.

New Inspections

  • Array used only with write access - If there is an array declared and updated somewhere in the code, but it is never read, it means that the array is very likely redundant and adds noise to the code. The inspection detects such cases and prompts you to remove the array to make the code cleaner.
  • Typed property might be unassigned - If a typed property does not have a default value, it is considered uninitialized. Reading uninitialized properties will generate a TypeError (unless magic __get() is defined). PhpStorm detects uninitialized properties and highlights code that attempts to read them.
  • Full Support for GitHub Pull Requests - The entire Pull Request workflow can now be done in PhpStorm, and there is no longer any need to switch to a browser. You can manage pull requests; view the timeline and inline comments; add comments and reviews; and accept changes.

OpenAPI Support

  • PhpStorm 2020.2 supports the OpenAPI Specifications plugin. This is a free plugin developed by JetBrains that provides completion, navigation, and validation in the OpenAPI spec files (openapi.yaml/openapi.json and swagger.yaml/swagger.json).
  • OpenAPI Support. The plugin also provides:
    • Swagger UI Integration.
    • Code generation.
    • Built-in structure Diff between OpenAPI specifications.
    • Gutter icons to create HTTP Client requests from specification.
    • Autocompletion for endpoints in HTTP Client.

New Inspections Widget and Problems View

  • In the top right-hand corner of the editor, you’ll see the brand new Inspections Widget with a summary of the problems in the current file.

Web Technologies

  • Prettier as the default formatter in JavaScript projects - Want to use Prettier instead of the built-in formatter to tidy up your code? With this update, it has become even easier than before. Just tick the new On code reformat checkbox and the IDE will use Prettier whenever you reformat your .js, .ts, .jsx, and .tsx files. Other file types can be easily added, too.
  • Best-in-class Vue.js support - Nuxt.js support, Vue-specific code style settings, improvements around Vue in TypeScript projects, and a lot of other things were added in the past year.
  • Save some time with new features for JavaScript - New smart Alt+Enter intentions will help you perform some actions faster. For example, you can now quickly convert a for loop with a numeric index into a forEach array method. Looking through documentation comments in JavaScript and TypeScript files has also become easier as you can now render them right in the editor, minimizing distractions.

Version Control

  • Support for Git installed in WSL 2 - PhpStorm 2020.2 supports Git installed in WSL 2 for working with projects located in Linux and Microsoft Windows file systems. The IDE can switch between Git executables depending on the project location. When a project is opened from WSL (via \\wsl$ path), the IDE will automatically switch to Git from WSL, and it will also provide you with the ability to use all the Git-related features in the IDE.
  • New UI to compare branches - When you want to compare two branches to see which commits do not belong to one another, PhpStorm 2020.2 will show the logs in the editor instead of the Git tool window. This will ensure that there is enough space to display all the information. Choose the Compare with Current action from the Git Branches popup menu VCS | Branches.
  • Drop commit action - You can now easily remove redundant local commits by selecting them in the Log tab of the Git tool window and choosing Drop Commit from the context menu.
  • Squash local commits - It is also possible to combine several local commits into one single commit, for example to clean up history before pushing. In the Git tool window, select commits and choose Squash Commits… from the context menu. The IDE will run an interactive rebase behind the scenes.

Database Tools

  • Separate editor for cell values - Now if you have a huge value in your cell, it can be viewed or edited in a separate panel. You can also toggle soft wrap mode using the right-hand toolbar. Use all the power of our code editor for your data.
  • Google BigQuery dialect - Added a new SQL dialect: Google BigQuery. Full support for BigQuery is not here yet, but all things must begin somewhere. So far, PhpStorm can correctly highlight and provide coding assistance for your queries if you use Google BigQuery.
  • DML preview - You can review the query that represents your changes in the data editor. There is a DML button that is active if there are pending changes. This query is not the exact SQL that will be run to modify your data, because PhpStorm uses a JDBC driver to update tables, but most of the time it will be the same.

Other Improvements

  • Customizing getters and setters.
  • Resolve for multiple projects in one window.
  • New action: Add Carets to Ends of Selected Lines.
PHP 8 Union Types





今すぐ JetBrains ライセンススペシャリストとライブ チャット