⬆️ ⬇️

PhpStorm 2019.2: PHP 7.4 Typed Properties, Duplicate Finder, EditorConfig, Shell Scripts, and More





Hello! We are pleased to present you the second major release of PhpStorm this year!



An overview of the release can be found on the “ What's new ” page. And under the cut, a detailed analysis of all the noticeable changes and new features. (Caution - a lot of pictures!)



You can download the new version on the website or using the Toolbox App . As always, a 30-day trial is available. The full version can be used by holders of an active subscription to PhpStorm or All Products pack, as well as free students and developers of open source projects.





PHP 7.4: typed properties



PHP 7.4 promises to be the coolest and most feature-rich release since PHP 7.0! Look at all the RFCs accepted in it .



The most anticipated feature is, of course, typed properties , and PhpStorm 2019.2 already fully supports them! Including backlight, output and type resolution, as well as all kinds of checks.



If you try to put something in the property, PhpStorm will immediately warn you about it.





But to prepare for the migration to PHP 7.4, which will be released in late November, PhpStorm has quick fixes. To declare a type, you can press Alt+Enter on a property without a type and select Add declared type for the field . PhpStorm will determine the type of a property based on the information in PHPDoc, the default value, or an argument type declaration, if the property is implemented through a constructor.





?? = operator (null coalesce assign)



The new short null check assignment operator is pretty handy for bulky expressions.



In PhpStorm, of course, the syntax is supported, but there is still a quick fix Alt+Enter in order to replace ?? where possible:





The decompression operator (...) in arrays



PHP supports unpacking arguments using an operator since version 5.6. In the upcoming release of PHP, the operator can be used in arrays:





PhpStorm will analyze the use of the operator for correctness and make sure that you unpack only arrays or Traversable objects and do not try to mistakenly do something not supported by the PHP interpreter:





In the next release of PhpStorm 2019.3, we plan to implement full support and quick fixes for all new PHP 7.4 features, including arrow functions, delimiters in numeric literals, etc.


Auto-injection of regular expressions in PHP



In previous versions of PhpStorm, regular expressions in PHP code didn’t highlight by default and displayed like regular strings. Of course, you could implement the RegExp language manually, but you won’t do this throughout the project.



PhpStorm 2019.2 added full support for regulars in PHP! This means that where preg_*, functions are used in the code preg_*, templates will be highlighted and checked for validity.





Moreover, now you can test the regular expression directly in the IDE! Hover over the template, press Alt+Enter and call Check RegExp .





Duplicate code highlighting on the fly



Finding duplicates in PhpStorm has been around for quite some time, in the menu Code → Locate Duplicates. If you haven’t tried it yet, try it - and be surprised how many repetitions can be in the project!



In this release, duplication analysis has reached a new level and works on the fly right in the editor. If you repeatedly copied or accidentally wrote the same pieces, then you will know about it instantly.



You can go to another duplicate or view everything in a list in a separate window:





By the way, these are good candidates for Extract refactoring.


The new inspection is called Duplicated code fragment and is enabled by default. The sensitivity threshold can be set in the Preferences | Editor | Inspections | General | Duplicated code fragment -> PHP . And in Preferences | Editor | Duplicates can set which elements are ignored when searching for duplicates, for example, you can ignore different names of variables, methods or properties, as well as constant values.



PHPT format support



Would you like to contribute to PHP itself and join PHP Internals? The best way is to start with documentation and tests! Fortunately, you don’t need to know C. For this, tests for PHP are written in special .phpt files. In fact, this is a text file, divided into several sections, some of which may contain PHP code.



So, in PhpStorm 2019.2 there is also support for phpt files! Sections are highlighted, PHP and INI are automatically implemented where necessary, transitions to external files in the corresponding sections work.





More information on writing tests for PHP is here: PHP TestFest Tutorials , PHP Internals Book and qa.php.net .



Running Composer through any PHP interpreter



Previously, to run Composer, you always needed a local PHP interpreter. The problem is that it may not exist at all or the environment may not correspond to the production. Now in PhpStorm 2019.2 you can run Composer through any interpreter configured in the IDE. For example, through Docker, Docker-compose, Vagrant or, say, a remote server via SSH.



To try this feature, select Remote Interpreter in the Preferences | Languages ​​& Frameworks | Php | Composer





Select an existing interpreter or add a new one!



Quick fixes



We break the list into several lines and vice versa



According to PSR-2 , a line longer than 80 characters in length should be split into several lines, each of which is shorter than 80 characters. Therefore, if you have a large array or the arguments / parameters of the function do not fit on the screen, then you can press Alt+Enter on them and select Split comma-separated values ​​into multiple lines:





If suddenly, as a result of refactoring, the list becomes shorter and fits on one line, then the reverse action is also available: Join comma-separated values ​​into a single line .



By the way, here you may need to quickly adjust the code style settings. In order not to search for the necessary options for a long time, select this piece of code, press Alt+Enter and call Adjust code style settings . PhpStorm will suggest changing only those options that are relevant for the selected lines:





Switch construct



We have implemented the ability to quickly add branches to switch designs. Press Alt+Enter on the case expression without the body and call Copy 'switch' branch .



Remember to edit the copied branch, otherwise PhpStorm will highlight the repeating piece:





PhpStorm 2019.2 will also warn if there is no default branch in switch , and you can also add it using a quick fix.



String manipulation



PhpStorm will help with routine string operations. Whatever you have to do with the string - split it into pieces, change the quotation marks, convert the concatenation to sprintf or interpolation, or anything else - press Alt+Enter on the string and select the desired action from the list.



In this release, we added a couple of new chips to this list.



Suppose you have a long expression in sprintf , and you need to add another parameter instead of a substring. Select it, press Alt+Enter , select Extract selected string part as format function argument , and PhpStorm will put the parameter in the right place:





You can also separate the substring by concatenation:





Preview for Structural Search



Structural search, or SSR for short, is a powerful tool that allows you to search for pieces of code not only as text, but as small syntax trees, while indicating node types or other filters. Try it: Edit → Find → Search Structurally ...



The problem with structural search is that describing a search pattern can be a non-trivial task. In PhpStorm 2019.2, fortunately, you can now see the real-time highlighting in the editor. There is no need to run the search again and again to debug the template.



Imagine, for example, that you want to find all the calls to a particular method of a class, but only those in which an object of another specific class is passed as a parameter. It will be difficult to find this with a regular search, but with an SSR - at a time!





HTTP client



CURL format support



Almost all web development and documentation tools now provide the ability to copy a query as a cURL string.



Now this line can be used in PhpStorm. Create a file with the extension .http or a new HTTP-request scratch file using the keyboard shortcut Cmd+Shift+N (Ctrl+Shift+Alt+Insert) , and then insert the query string cURL. It will be automatically converted to a full query, and then you can conveniently experiment with headers and other query parameters.





HTTP client stores cookies



Suppose you are testing a service and making a request to authenticate, and then in the next request call a private endpoint. Previously, a cookie with session information from the first request would be lost. And in 2019.2 all cookies are stored and transmitted in subsequent requests.





If you do not want cookies to be saved, use the @no-cookie-jar tag for a specific request.



Version control



A new way to commit without dialogue



Suppose you change several files in different folders of a project. To commit them, you go to the Local Changes tab of the Version Control window, select the necessary files and call the commit dialog. At this point, everything is blocked by a pop-up window, and you can not see the project.



In PhpStorm 2019.2, you can commit directly from the Local Changes tab.


Now, working on the commit, you can view the entire project, history and, in general, do anything in the IDE.





The feature is disabled by default. To try it, check “Commit from the Local Changes without showing a dialog” in Preferences | Version Control | Commit Dialog.



Related File Reminders



When you make a commit, PhpStorm 2019.2 can tell you to add files that used to change frequently along with those that you have already selected for the commit.





Improved work with .gitignore



PhpStorm supports .gitignore out of the box and highlights ignored files in the Project view .



It has become a little easier to add to .gitignore . This can be done in the Version Control window by calling Add to .gitignore from the context menu on files that have not yet been added to the version control system.





The .gitignore file .gitignore now has path completion, and by Cmd+click file will be highlighted in the Project view .





You can hide author, data or hash columns in the log.





Comparing the current state with any branch



To do this, just call the Show Diff with Working Tree command from the Git Branches popup, which is shown by clicking on the name of the current branch in the lower right corner.





Directory history from Project View



You can select multiple folders in Project View and see the change history for them using the Git | Show History from from the context menu.





Docker



We moved Docker to the new Services window. The purpose of this window is to collect all connections and running processes in one place. So far, by default, PhpStorm includes Docker and database connections there. You can also add any Run / Debug configurations to the Services window. This is available in the Configurations available in Services section of Run | Edit Configurations ...



All services are displayed as nodes, but each of them can be made a separate tab by calling Show in New tab or simply dragging the node with the title of the Services window.





View Docker Container File System



You can navigate through the contents of the container on the Files tab.





Editor



Typing code completion



If you suddenly wrote funtcion or fnction instead of function , it’s not scary, because the add-on will work anyway, as it recognizes this kind of typo.





This works in all languages ​​and for all characters - keywords, classes, functions, properties, methods, etc.



Behavior Configuration 'Move Caret to Next Word'



You can choose where the cursor will be placed when moving through words. See the Caret Movement section in Preferences | Editor | General



<



Move beyond brackets and quotation marks when pressing Tab



The old chip is now enabled by default. When you type and press Tab, instead of adding a tab character, your cursor will move outside the quotes and brackets. To disable this feature, uncheck the Jump outside closing bracket / quote with Tab when typing checkbox in the Preferences | Editor | General | Smart keys





The highlighted code is wrapped in quotation marks or brackets automatically



Another super useful feature is now enabled by default. When you click a quote (or bracket) to select a piece of code, quotes (or brackets) will be automatically added at the beginning and end of the selection.





If you don’t like this behavior, you can turn it off by checking Surround selection on typing quote or brace in the Preferences | Editor | General | Smart keys



New default layout on macOS



We changed the default layout on macOS from Mac OS X to macOS 10.5+. We also renamed layouts: Mac OS X 10.5 is now called Default for macOS, and the old Mac OS X is now IntelliJ IDEA Classic.



Syntax highlighting for over 20 languages



If your project has files in programming languages ​​other than PHP and JavaScript, then PhpStorm 2019.2 you will be pleasantly surprised by the syntax highlighting for Python, Ruby, Go and a whole bunch of other languages. This works out of the box and does not require any additional settings.



With this, we want to improve the experience of using PhpStorm for users who sometimes need to look at code in other languages. PhpStorm is still mainly a PHP and web development environment , so we do not plan to extend the support of other languages ​​beyond the limits of highlighting.





Syntax highlighting for additional languages ​​is based on TextMate grammars. See the full list of languages ​​supported out of the box at Preferences | Editor | TextMate Bundles .



Shell scripts



In PhpStorm 2019.2, we implemented extensive support for shell scripts, including path additions, Rename refactoring, code generation ( Cmd+N/Alt+Insert) and a bunch of live templates ( Cmd+J/Ctrl+J) .





Also implemented integration with several external tools.



To find potential problems in scripts, PhpStorm will suggest installing Shellcheck , which finds a ton of problems and provides quick fixes for them.



Also in PhpStorm 2019.2 it integrates with the mvdan / sh tool for formatting shell scripts. When you call Reformat Code for the first time, the IDE will prompt you to install it and then format it correctly.



And finally, there is integration with the Explainshell website. You can select any command, press Alt+Enter and select the Explain shell . The IDE will redirect to Explainshell , where you can see what the selected set means. When you hover over a command directly in the IDE, a help is also displayed.





EditorConfig



By adding the .editorconfig file, you make development in the team more enjoyable, as certain style options will work the same for everyone regardless of the editor used.



Previously, in PhpStorm, it was required to install the EditorConfig plugin, but in 2019.2 it is available out of the box and no additional steps are required.



You can set different settings for different subfolders in the project. Just create .editorconfig files in the necessary folders - there can be as many of them in the project.



You can also set PhpStorm ! Options in the .editconfig file!


In addition to the standard options for EditorConfig, you can configure almost all the style options specific to PhpStorm. Previously, they could only be configured from the UI. Such options are indicated by the ij_ prefix to differ from the standard ones.





If you create a new .editorconfig file from Project View , then PhpStorm will prompt you to choose which options to include in the created file. They will be added commented out, and the necessary ones can be uncommented and changed.





Appearance



More information in Project View



You can enable the display of file size and modification date in Project View using View -> In-place Descriptions .





A new kind of inspection tooltip



The tooltip now not only describes the problem, but also offers the first fix from the list. To apply it instantly, even without a hint or click, press Alt+Shift+Enter . To see all available fixes, press Alt+Enter .





Updated UI on Windows



Fresh frameless view on Windows 10:







PhpStorm, as always, includes all updates from WebStorm and from DataGrip. A complete list of changes can be found in very large release notes .



And, finally, a short video (in English) with a demonstration of the main features of the release:





That's all for once. Thank you for reading to the end! Questions, wishes, bug reports and just thoughts express in the comments! We will be happy to answer.



Your JetBrains PhpStorm Team



')

Source: https://habr.com/ru/post/461449/



All Articles