Change signature refactoring in PhpStorm
A very powerful refactoring is the Change signature refactoring in PhpStorm. It enables us to modify a function signature in many ways: we can change the function name, change its visibility, add, remove and reorder parameters as well as rename parameters.
Take the searchUser function in a class called UserReporsitory.
There is no real use for this method as it is now. It’s private, so no other classes can make use of this function. It also has no parameters where we want to be able to search users based on their username. Using the Refactor | Change Signature… context menu (Ctrl+F6 or Cmd+F6 on Mac) we can open the Change Signature dialog.
In this dialog, we can change the function’s visibility from private to protected or public. We can rename it to searchUserByUsername so that the intent of this function is clearer to the caller. Next, we can add a parameter $username and give it a default value, in this case an empty string. Note that we can also add the parameter type (e.g. MyNamespace\MyType $username) as well as an initializer (e.g. $username = null). We can reorder parameters using the buttons on the right.
The Change Signature dialog shows us a preview of the new function signature. We can use the Refactor button to immediately carry out the refactoring or the Preview button to see a list of all code that is about to be updated with this new signature. Once done, our new searchUserByUsername function will look like this:
What’s really interesting is that all calls to this method have been updated as well. For example, the following call has been updated to use the default value we entered in the Change Signature dialog earlier:
The Change Signature refactoring will update the function itself, all calling code, and overloading functions in the case of interfaces or abstract class functions being refactored. Using the Alt+G shortcut (or clicking the Propagate Parameters button) lets us add new parameters to all calling functions as well.
As always, we appreciate your feedback in the comments below or in our forums!
Develop with pleasure!
– JetBrains Web IDE Team
Working with Windows Azure SQL Database in PhpStorm
PhpStorm provides us the possibility to connect to Windows Azure SQL Database right from within the IDE. In this post, we’ll explore several options that are available for working with Windows Azure SQL Database (or database systems like SQL Server, MySQL, PostgreSQL or Oracle, for that matter): …
Folding for imports in PhpStorm 6.0
In PhpStorm 6, we've introduced code folding for imports. Any list of imports will now be folded into a single line. This greatly reduced clutter in your editor when having a lot of imports! (more…)…
Drag & Drop Project Files to Remote Hosts in PhpStorm
The Remote Host pane allows us to work directly on a remote server through FTP, FTPS, SFTP or a local/network folder. A lot of people asked us to add drag & drop to the Remote Host pane in PhpStorm. Good news: PhpStorm 6 comes with drag & drop as well as copy & paste support from the pro…