“Make Static” Refactoring Tool in PhpStorm 11
When refactoring, sometimes you wish to change your methods to be static, while this isn’t the best practice in the world, it’s possible you’ll be in a position where pragmatism will take priority over great design. If you are 100% percent certain that you won’t need to mock something, then use the new Make Static refactoring tool in PhpStorm 11 to ruin your future `self::`’s day.
If you want to make a simple method static, it’s as easy as placing the caret over the function name, and selecting the Make static option from the Refactor drop down menu. For simple methods with no access to the object, you can just deselect the Add object as a parameter with name checkbox, and click Refactor.
If your function is simple enough (it doesn’t need any parameters, or rely on accessing properties or methods of this object), you’ll get the static method made with no interaction and no fuss.
For more complex refactors, where you currently make use of the existing object via `this`, you’ll need to pass in an instance of the object via a parameter, by selecting the Add object as a parameter with name checkbox option, and giving the parameter a name.
Where you access the properties of the class, you can use the Add parameters for fields section to pass the value of the property in as a parameter instead of accessing the object inside the newly created static method.
While I heartily discourage you using this functionality, it’s nice to know that if you do choose to go down this route, PhpStorm has got you covered.
– Gary and the PhpStorm Team
The Drive to Develop!
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…