PhpStorm 2021.1: PHP and HTML File Previews, 20+ New Inspections, and Pair Programming with Code With Me





We are glad to present you the first major release of PhpStorm this year! Below the cut is a detailed analysis of all the changes and new features.



PHP



  • Preview PHP and HTML files directly in the editor using the built-in browser and local PHP interpreter.

  • 20 PHP.

  • , PHP, — Settings / Preferences.

  • PHP composer.json.

  • SQL, RegExp . . .

  • SQL- CMS.

  • .



IDE



  • Split .

  • JSONPath JSON-.

  • JSON Lines.

  • Preferences | Editor | Font.



Docker



  • Dockerfile.

  • Dockerfile.



Version Control



  • - GitHub — IDE .



Code With Me



  • JetBrains PhpStorm . Code With Me , - .





You can download PhpStorm 2021.1 on the website or in the Toolbox App .



This is briefly, and now more about everything.



PHP



PHP version selection via statusbar



In the previous release, we added the PHP version indicator to the status bar. In 2021.1, the version can be changed regardless of the one specified in the composer.json



. This will allow, for example, to quickly check the compatibility of the code with newer PHP versions.









Easily find PHP settings



Most of the PHP related preferences are now available in Settings / Preferences | PHP .









View PHP and HTML files in the editor



When you hover over any place in the editor, a pop-up window with browser icons appears in the upper right corner. By clicking on the icon, the current file will open in the selected browser.



Now there is also a PhpStorm icon here. When you click on it, the file will open for preview right in the editor.



The preview works on HTML and PHP files, as well as all associated CSS and JavaScript files.







Open the file and start typing - the preview tab will instantly show all the changes.



PhpStorm uses a local PHP interpreter that can be specified for the project in Settings / Preferences | PHP. Docker .



, , Preferences | Tools | Web Browsers For HTML files.



Alt+F2.





SQL-



Many CMS and frameworks allow prefixing tables. This can be useful when using the same database for multiple applications.



Previously, integration with database tools was lost because the table names were generated dynamically.



Now you can specify the prefix in the .phpstorm.meta.php file . You can read more about metafiles and how to specify table prefixes on the help page .



Let's say we have the following request in a Drupal application:











As you can see, PhpStorm cannot resolve either the table name or the column names. This is because we have specified the table prefix in the Drupal configuration.



To fix this, add a file .phpstorm.meta.php



with the following content to the project :



namespace PHPSTORM_META {
 override(
  //       SQL-
   sql_injection_subst(),
   map([
     '{' => "PS2021_", //  `{`   SQL    
     '}' => '',       //   `}`    
   ]));
}
      
      







Now PhpStorm will be able to bind SQL queries to data sources and provide you with such features as auto-completion, transition to data view, and more.







By the way, if the request is formed through concatenation, then this will also work:



<?php
const DB_PREFIX = "mydatabase_";
$sql = "SELECT * FROM " . DB_PREFIX . 'table_name';
      
      







Inspections and quick fixes



In this release, we have added over 20 different checks and quick fixes to help prevent errors in the early stages of development. You can view the full list of inspections and configure them in Settings / Preferences | Editor | Inspections .



When a problem occurs, hover over it, press Alt + Enter and select the suggested quick fix.



And now more about some of the new inspections.



Simplifying `if` blocks with the same bodies



Some blocks if



and else



may be redundant. For example, you could change them, as a result of which their bodies were completely or partially the same.



PhpStorm will detect such extra blocks and offer to remove them:











Moreover, if only a part of the body is repeated, PhpStorm will offer to extract only it:







Inversion of `if`



If you press Alt + Enter for any if



, you will be prompted for the “Invert` if` statement ”command . It reverses the condition and makes the necessary adjustments to preserve the logic.



If you like to use early return , then this inspection will come in very handy when refactoring your code.



For example :







In loops, this works too:





Replacing `isset` with ??



The code isset($a) ? $a : $b;



is identical $a ?? $b



, so PhpStorm will highlight it and suggest a quick fix for replacement.







, —  , .



Code | Run Inspection by Name... , `isset` can be replaced with coalesce. .



`isset` `!== null`



Use isset()



only makes sense for arrays and variables. In all other cases, it is better to check the operand for null



.



PhpStorm will highlight such places and allow you to replace with Alt + Enter isset()



to compare with null



.







Variable in `foreach` overwrites an already declared variable



Variables for key and value in the loop foreach



can conflict with the names of other variables or parameters.



The problem is that PHP doesn't have a separate scope for them. That is, the value will be overridden - probably contrary to expectations.



PhpStorm will highlight such places because they are potential sources of bugs.







Unnecessary curly braces for variables within strings



PhpStorm highlights redundant curly braces in the context of string interpolation, prompting you to remove them and make your code cleaner.







Simplifying Boolean Expressions



If the boolean expression contains literals true



or false



, then it can probably be simplified and made more readable.



PhpStorm will highlight such expressions and allow you to simplify them using Alt + Enter.







Strict comparison with incompatible types



The operator ===



will always return false



if the operands are not of the same type.







PhpStorm now highlights such places because they can be sources of bugs. At the same time, PhpStorm will take into account all deduced types and help find problems in not the most obvious cases.







Insecure links http: //



Protocol usage http://



in strings is now highlighted. The IDE offers a quick-fix for quick replacement http://



to https://



(by Alt-Enter). You can also use it to add a URL to the list of ignored links.







Suspicious name combinations



PhpStorm highlights some common errors in naming parameters or return values, such as $needle



and $haystack



or $x



and $y



.



Usually such errors are a symptom of a bug or, at the very least, are very confusing.







Replacing `define` with` const`



PhpStorm detects cases where a constant declaration via define



can be replaced with a more readable syntax const



. With Alt + Enter, you can make a replacement.







Configuring pre-commit inspections



You can now select an inspection profile to be used to analyze your code before committing to Git.



Click on the gear icon, check the Analyze code checkbox , click Configure and select the desired profile.







You can create your own profiles in Settings / Preferences | Editor | Inspections .



Other



Artificial scope for refactoring



Cycles foreach



, for



, while



and blocks catch



in PHP are not insulated scope. This is rather inconvenient when you are renaming variables, because it also renames variables outside of the desired block.



In PhpStorm 2021.1, we added an artificial scope for all such blocks. Now, when calling the Rename refactoring (Shift + F6), renaming will be more intuitive.









Improving automatic tongue injection



Previous versions of PhpStorm were able to define the language for arguments only. For example, if you passed a string to a function preg_*



, it was highlighted as a regular expression.



But if you used a variable, then its value was not highlighted in any way.



PhpStorm 2021.1 analyzes the use of variables and is able to automatically implement the desired syntax.









Using extensions from the `suggest` block in composer.json



The codebase can contain classes from PHP extensions. So far PhpStorm has checked if these extensions are added to sections require



in the file composer.json



.



PhpStorm 2021.1 takes into account the specification of extensions not only in the `require` section, but also in the` suggest` section.



More importantly, PhpStorm now warns if an extension has been added to suggest



in composer.json



, but is used without type checks extension_loaded()



or function_exists()



.



A special quick fix will allow you to add an extension to require/require-dev.











Important fixes



We have fixed over 2400 tickets opened by our users and the JetBrains team in the PhpStorm tracker. Some of the most interesting are:

  • WSL 2 Docker (WI-53396).

  • Quality tools docker-compose exec- (WI-55840).

  • PHP (5000 ) (WI-31569).

  • (WI-58306).





Code With Me



Code With Me is JetBrains' new collaborative development and pair programming tool. We originally introduced it in PhpStorm 2020.3. The tool has been improved a lot in this release.







First, it became possible to flexibly set access rights for accomplices.



Secondly, now guests do not even need to install an IDE - just execute a console command, and the free client will be downloaded automatically.



Thirdly, built-in voice and video calls, as well as a messenger have been added.



Enterprise teams and other high security teams can now run their Code With Me server on a private network.



Read more about Code With Me on the JetBrains website .



IDE



Expanding Tabs in Split Mode



You can open multiple tabs at the same time in Split mode by simply dragging the tab to the desired corner of the screen.



You can now also double-click on a tab to expand it fully. You can also return the tab to its previous state by double-clicking.









JSONPath support



You can now use JSONPath queries to quickly search large JSON documents. The feature is available in the section Edit | Find | Evaluate JSONPath .









JSON Lines support



PhpStorm now supports JSON Lines format for working with structured data and logs. The IDE recognizes .jsonl , .jslines , .ldjson, and .ndjson files .









Typography settings



You can vary the main and fallback fonts. New options are available in the Typography Settings in the Settings / Preferences | Editor | Fonts .







Docker



Completion of image names in Dockerfile



Start typing the name of the image and PhpStorm will offer you a list of images available on the Docker Hub:







Folding in multistage Dockerfiles



When using multiple sections in a Dockerfile, FROM



you can collapse any of them and they will be separated by a line for better readability.







Cancel Docker run



You can easily stop execution of a running Dockerfile from the Services window . Select Stop Deploy from the context menu for the launched item.





Improvements for GitHub pull requests



To create a pool rekvest, just click the "+" in the window Pull Requests or go to Git | GitHub | Create Pull Request .



In the updated dialog, you can:

  • Select base and head branches from the list of available branches.

  • View modified files in the Files tab.

  • Edit names and descriptions of pull requests, assign reviewers and performers, add tags.

  • Create draft pull requests.









PhpStorm 2021.1 also supports pull request templates. Add a file pull_requst_template.md



to the project and specify the template text in it - and every time you create a new pull request, this description will be filled in automatically.



Template support for Git commits



PhpStorm now respects the template specified in commit.template



your Git config parameter when creating a commit message .



HTTP client



SSL support



Now you can specify SSL settings in the HTTP client. Click the Add environment file button and select Private . File will be created in which you can specify the SSL settings: clientCertificate



, hasCertificatePassphrase



, clientCertificateKey



, verifyHostCertificate



.









Improvements for OpenAPI / Swagger



PhpStorm has support for OpenAPI specifications and built-in Swagger UI.



Now Swagger UI supports specifications with external files connected via $ref



.







DB Tools





PhpStorm includes built-in DataGrip capabilities : a permissions interface, Live Templates contextual templates, simplified navigation, and more. Read more about these features in the DataGrip 2021.1 release overview from our colleagues.



Web





And as always, PhpStorm includes all the updates from WebStorm 2021.1 : smarter auto-completion for JavaScript and TypeScript, extended Stylelint support, and more.






And here is a video (in English) where we demonstrate the main features of this release:





That's all for now. We will be glad to receive your feedback - questions, wishes, bug reports and just thoughts. Leave them in the comments below.



All Articles