‘Extract Function/Method’ refactoring for PHP
We are working hard on new features for PhpStorm 2.1, and the ‘Extract Function/Method’ refactoring for PHP is one of them. This feature has been available since the first PhpStorm 2.1 EAP(106.444), and we are looking forward for your feedback.
The main point of the refactoring is to convert a part of a larger function/method into a new function/method. This might be useful if you need to make your code easier to understand or reuse a specific code fragment.
Let’s try to put this refactoring into practice.
Select a code fragment (Picture 1a) or an expression (Picture. 1b).
Picture 1a: Select a code fragment
Picture 1b: Select an expression
Invoke the refactoring from the menu ‘Refactor -> Extract Method‘ or using a hotkey. The default hotkey is Ctrl+Alt+M for Windows/Linux and Cmd+Opt+M for Mac.
Depending on the context of the selected code fragment, ‘Extract method’ (the code fragment is inside a method) (Picture 2b) or ‘Extract Function'(the code fragment is inside a function or script) (Picture 2a).
Picture 2a: ‘Extract Function’ dialog
Picture 2b: ‘Extract Method’ dialog
Enter the name of the new function/method. Press OK.
Picture 3a: The code fragment is replaced with a function call statement
Picture 3b: The expression is replaced with a method call expression
Picture 4a: Definition of the extracted function
Picture 4b: Definition of the extracted method
Develop with pleasure!
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): …
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. (more…)…
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…