{"id":21781,"date":"2020-06-22T13:22:18","date_gmt":"2020-06-22T13:22:18","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=15774"},"modified":"2020-07-14T16:55:44","modified_gmt":"2020-07-14T16:55:44","slug":"phpstorm-2020-2-eap-4","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/phpstorm\/2020\/06\/phpstorm-2020-2-eap-4\/","title":{"rendered":"PhpStorm 2020.2 EAP #4"},"content":{"rendered":"<p>The Early Access Program for PhpStorm 2020.2 is in full swing, and today we\u2019ve got Build 4 of the 2020.2 EAP for you.<\/p>\n<p>Read on to learn about the new control flow engine, the <em>Add caret per selected line<\/em> action, and smart handling of terminal commands.<\/p>\n<p>If you prefer to watch rather than read, check out our EAP video series on the <a href=\"https:\/\/www.youtube.com\/channel\/UCGp4UBwpTNegd_4nCpuBcow\" target=\"_blank\" rel=\"noopener\">JetBrainsTV<\/a> YouTube channel. <a href=\"https:\/\/www.youtube.com\/watch?v=vzXaqrMUvSg\" target=\"_blank\" rel=\"noopener\">Episode 1<\/a> is already available.<\/p>\n<p align=\"center\"><a class=\"jb-download-button\" href=\"https:\/\/www.jetbrains.com\/phpstorm\/nextversion\/\" target=\"_blank\" rel=\"noopener\"><i class=\"download-icon\"><\/i>Download PhpStorm 2020.2 EAP<\/a><\/p>\n<p><!--more--><\/p>\n<h2 id=\"new_control_flow_engine\">New control flow engine<\/h2>\n<p>PhpStorm 2020.2 introduces a new version of the control flow engine, which is now more powerful than ever. We\u2019ve already shown some improvements in the <a href=\"https:\/\/blog.jetbrains.com\/phpstorm\/2020\/05\/phpstorm-2020-2-early-access-program-is-now-open\/#php_control_flow_analysis_reworked\">EAP#1 post<\/a>. Let\u2019s explore what it offers in more detail by looking at some scenarios from real-life projects.<\/p>\n<h3 id=\"condition_always_true\">Condition always true<\/h3>\n<p>Let\u2019s start with the new <em>Condition always true<\/em> inspection:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15777\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_true-2.png\" alt=\"always_true\" width=\"2060\" height=\"868\" \/><\/p>\n<p>In this code snippet, PhpStorm understands that <code>$item<\/code> must always have the type <code>FOFTable<\/code>, as otherwise the function returns <code>false<\/code>. As a result, <code>is_object($item)<\/code> is always true, and the whole ternary operation can be simplified.<br \/>\nTo help you more easily understand what\u2019s going on, the inspection message provides detailed information about the cause. There is also a quick-fix that lets you navigate to the expression that uniquely defines the current value.<br \/>\nHere is another example of this inspection in action:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15778\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_true_2.png\" alt=\"always_true_2\" width=\"2042\" height=\"924\" \/><\/p>\n<p>PhpStorm knows that as part of the <code>elseif<\/code> chain, the case with <code>$stubContent === null<\/code> has already been covered, so the last condition can be simplified.<br \/>\nThere are several other new inspections based on the new engine, including <em>Expression is always \u2018null\u2019<\/em>, <em>Result of \u2018instanceof\u2019 is always \u2018true\u2019, <\/em>and <em>Variable is always true\/false when reached.<\/em> Let\u2019s look at them in more detail.<\/p>\n<h3 id=\"result_of_instanceof_is_always_true\">Result of \u2018instanceof\u2019 is always \u2018true<\/h3>\n<p>Suppose we have the following non-trivial hierarchy:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15779\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-hierarchy.png\" alt=\"hierarchy\" width=\"2072\" height=\"1008\" \/><\/p>\n<p>Inside <code>ConfigEntityBase<\/code>, we have the following code:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15780\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_true_3.png\" alt=\"always_true_3\" width=\"2056\" height=\"516\" \/><\/p>\n<p>Because <code>ConfigEntityBase<\/code> implements <code>ThirdPartySettingsInterface<\/code>, the expression is always true. PhpStorm highlights it as redundant and displays a warning that suggests unwrapping the <code>if<\/code> statement for clarity.<\/p>\n<h3 id=\"variable_is_always_true_false_when_reached\">Variable is always true\/false when reached<\/h3>\n<p>PhpStorm not only analyzes conditions but also tracks the values of variables. It can suggest increasing code readability by replacing the always true\/false variables with the corresponding boolean values.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15793\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_true_6.png\" alt=\"always_true_6\" width=\"2076\" height=\"654\" \/><\/p>\n<p>In this example, the ternary operator makes sure that <code>$empty<\/code> is always true in the first branch, so we can safely replace the variable with just the <code>true<\/code> value.<br \/>\nThe inspection is disabled on purpose for the case below. This is because, according to our investigations, such code is often used to quickly change the default value:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15792\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_true_5.png\" alt=\"always_true_5\" width=\"1986\" height=\"400\" \/><\/p>\n<h3 id=\"expression_is_always_null\">Expression is always \u2018null\u2019<\/h3>\n<p>In addition to true\/false values, PhpStorm now also tracks the null value of the variable. Let\u2019s take a look at the <em>Expression is always \u2018null\u2019<\/em> inspection.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15783\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-always_null.png\" alt=\"always_null\" width=\"2038\" height=\"1140\" \/><\/p>\n<p>In this example, PhpStorm builds the control flow and sees that the assigned <code>null<\/code> value isn\u2019t rewritten, neither by a new assignment nor by a pass-by-reference call. The IDE highlights the usage of <code>$default<\/code> and suggests simplifying the expression to make it more clear.<\/p>\n<h2 id=\"add_caret_per_selected_line_action\">Add caret per selected line\u00a0action<\/h2>\n<p>The new <em>Add Caret Per Selected Line <\/em>action creates carets at the end of each selected line, and deselects the lines. Invoke it using the shortcut <em>Alt+Shift+G<\/em> on Windows\/Linux or <em>\u2325\u21e7G<\/em> on macOS.<\/p>\n<p><img decoding=\"async\" class=\"alignleft size-medium wp-image-15803\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-add_caret_action.png\" alt=\"add_caret_action\" width=\"598\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-add_caret_action.gif\" \/><\/p>\n<h2 id=\"smart_handling_of_terminal_commands\">Smart handling of terminal commands<\/h2>\n<p>PhpStorm has many features that can help you do specific jobs faster. In the upcoming v2020.2, if you run certain commands from the built-in terminal, the IDE will now suggest using existing IDE features instead.<br \/>\nLet\u2019s say you want to check commit logs. If you type <code>git<\/code> <code>log<\/code> in the built-in terminal, the IDE will highlight the command in a different color, indicating that it can be handled by the IDE itself. Press <em>Ctrl+Enter<\/em>, and the IDE will open the <em>Git<\/em> tool window on the <em>Log<\/em> tab so you can explore commit logs with less effort.<\/p>\n<p><img decoding=\"async\" class=\"alignleft size-medium wp-image-15805\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-terminal_smart_commands.png\" alt=\"terminal_smart_commands\" width=\"808\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/06\/phpstorm-terminal_smart_commands.gif\" \/><\/p>\n<p>This is still a work in progress, so we\u2019d love to hear what other PHP-related commands you would like PhpStorm to handle in a similar fashion.<br \/>\nIf you don\u2019t find this feature useful in your workflow, you can disable smart commands by unchecking <em>Smart command handling<\/em> in <em>Preferences\/Settings | Tools | Terminal<\/em>.<\/p>\n<hr \/>\n<p>The full list of changes, including bug-fixes and improvements, is available in the <a href=\"https:\/\/confluence.jetbrains.com\/display\/PhpStorm\/PhpStorm+202.5792.59+Release+Notes\" target=\"_blank\" rel=\"noopener\"><strong>release notes<\/strong><\/a>.<\/p>\n<ul>\n<li><strong>Important!<\/strong> PhpStorm EAP builds are not fully tested and may be unstable.<\/li>\n<li>You can install an EAP build side by side with a stable PhpStorm version to try out the latest features.<\/li>\n<li>EAP builds are <em>free<\/em> to use but expire 30 days after the build date.<\/li>\n<\/ul>\n<p>Please report any problems you find to our <a href=\"https:\/\/youtrack.jetbrains.com\/issues\/WI\" target=\"_blank\" rel=\"noopener\">issue tracker<\/a>, or by commenting on this post. Your feedback is much appreciated, and the most active EAPers will get special <a href=\"https:\/\/twitter.com\/Mark_Baker\/status\/1221049276362522624\" target=\"_blank\" rel=\"noopener\">limited-edition gifts<\/a> from us!<\/p>\n<p>Your JetBrains PhpStorm team<br \/>\n<em>The Drive to Develop<\/em><\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[826],"tags":[790,2678,600,602,2004],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21781"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/phpstorm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=21781"}],"version-history":[{"count":2,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21781\/revisions"}],"predecessor-version":[{"id":57822,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21781\/revisions\/57822"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=21781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=21781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=21781"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=21781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}