locate duplicate code -> build function
Hello!
In my file is double code.
I display this code.
Is there a tool that converts the code into a function?
Since I now have PhpSorm version 6.0 !! :)
Sincerely yours
Stephan
Please sign in to leave a comment.
Hi there,
Please select such code and try "Refactor | Extract | Method..."
Hello!
Thanks for the information.
Unfortunately, the result is not as hoped.
I have a file.
--------------------------
function test1 () {
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
function test2 () {
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
function test3 () {
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
------------------------------
This file is duplicate code.
With code -> Locate Duplicates ..
can I find duplicate code.
If I use the duplicate code
Refactor -> Extract -> Method ...
alters I get the file.
-------------------------------
function test1 () {
myDuplicateCode ();
}
myDuplicateCode function ()
{
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
function test2 () {
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
function test3 () {
$ aaa = "aaaaa";
$ bbb = "bbbbb";
$ ccc = "ccccc";
}
-------------------
Why not in the other functions?
Sincerely yours
Stephan
Other functions/places you have to do manually -- you can do such "replacement" from the same screen actually:

So ... in your example, After you've executed Code | Refactor | Extract Method:
After making these operations the result will be: