Make Method Static
The Make Method Static refactoring converts an instance method to a static one and automatically corrects all calls, implementations and overridings of the method.
Performing the Refactoring
- Select the method to be refactored in the Structure view, or right-click the method name in the editor. On the main menu, or on the context menu of the selection, choose . If your method does not need any parameters, nor rely on accessing properties or methods of this object, you will get the static method made silently, without displaying any dialog boxes: Make Method Static dialog box opens.
- If you currently use the existing object via
this
, select the Add object as a parameter with name checkbox to pass in an instance of the object via a parameter. In the text box below, specify the name of the parameter to be generated. After the refactoring, the new parameter will be documented in the PHPDoc block. - If you access the properties of the class, use the Add parameters for fields area to pass the value of the property as a parameter instead of accessing the object inside the newly created static method.
- Select the Add parameters for fields check box.
- In the Parameters list, which shows all the possibly suggested parameters, select the check boxes next to the ones that you want to pass the values in.
- To preview the results, click Preview and examine the reuslt of the refactoring in the Find tool window. Apply the changes, if no issues arizs.
See Also
Reference:
Last modified: 19 July 2017