{"id":19746,"date":"2015-09-25T10:56:05","date_gmt":"2015-09-25T10:56:05","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=8999"},"modified":"2024-01-09T14:59:12","modified_gmt":"2024-01-09T13:59:12","slug":"introducing-parameter-refactoring-in-phpstorm-9","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/phpstorm\/2015\/09\/introducing-parameter-refactoring-in-phpstorm-9\/","title":{"rendered":"Introducing Parameter Refactoring in PhpStorm 9"},"content":{"rendered":"<p>PhpStorm users got a great new refactoring tool in PhpStorm 9\u00a0\u2013 parameter refactoring. Here&#8217;s a quick explanation on how to use this cool new tool.<\/p>\n<p><!--more--><\/p>\n<p>It&#8217;s easy to refactor a value that is being used inside a function so that it needs to be passed into the function as a parameter. Suppose you have a function that defines a value inline:<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2015\/08\/phpstorm-refactor-parameter-1.1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-9010\" alt=\"Refactor Parameter\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2015\/08\/phpstorm-refactor-parameter-1.1.png\" width=\"600\" height=\"181\" \/><\/a><\/p>\n<p>Here, we&#8217;d like to pass the filename into the function as a second parameter, rather than have it generated inline in the <em>file_put_contents<\/em> call.<\/p>\n<p>If we highlight the <em>date(&#8216;dYM&#8217;) . &#8216;.log&#8217;<\/em> string, and press<strong>\u00a0CMD\/CTRL + ALT + P<\/strong>\u00a0(or\u00a0<strong>CTRL + T<\/strong>\u00a0plus\u00a0select 6<em>.<\/em> for <em>&#8220;Parameter..&#8221;), <\/em>PhpStorm will ask what we want to name the new parameter. In this case I&#8217;d like to call it\u00a0<em>filename<\/em>, so I enter that name into the prompt. Once we confirm the name, the function will have been refactored:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-9011\" alt=\"Refactor Parameter\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2015\/08\/phpstorm-refactor-parameter-2.png\" width=\"600\" height=\"143\" \/><\/p>\n<p>Notice how PhpStorm has moved the generation of the filename string into the call to the\u00a0<em>writeToLogFile<\/em> function, and added the\u00a0<em>$filename<\/em>\u00a0parameter to the function definition and to the first parameter in the\u00a0<em>file_put_contents<\/em> call.<\/p>\n<p>If you would like to only move\u00a0<strong><\/strong><em>part\u00a0<\/em>of a string into a parameter, then simply highlight the part you wish to move and again press <b style=\"color: #000000;\">CMD\/CTRL + ALT + P<\/b>. PhpStorm will now ask you what you want to name the new parameter, and whether you would like to\u00a0the string and new parameter, or embed into the string using double quotes.<\/p>\n<p>Keep up with the latest PhpStorm news on our\u00a0<a title=\"PhpStorm Blog\" href=\"https:\/\/blog.jetbrains.com\/phpstorm\/\" target=\"_blank\" rel=\"noopener\">blog<\/a>\u00a0and follow us on Twitter\u00a0<a title=\"Follow PhpStorm on Twitter\" href=\"https:\/\/twitter.com\/phpstorm\" target=\"_blank\" rel=\"noopener\">@phpstorm<\/a>.<\/p>\n<p><em>Develop with pleasure!<br \/>\n&#8211; JetBrains PhpStorm Team<\/em><\/p>\n","protected":false},"author":1152,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[826,808,907],"tags":[2345,195],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19746"}],"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\/1152"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=19746"}],"version-history":[{"count":1,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19746\/revisions"}],"predecessor-version":[{"id":432102,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19746\/revisions\/432102"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=19746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=19746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=19746"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=19746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}