Dealing with large volumes of unorganized code? Do you have Organizational OCD like me? Party people, your dreams have now been fulfilled.
The Alphpetize plugin for Sublime Text scans your PHP file for class methods and organizes them by visibility and function name.
If you are using the Sublime Package Manager, you can install Alphpetize by selecting Package Control: Install Package
under the Sublime Text > Preferences > Package Control
menu item. Type Alphpetize
and install!
Clone the package into your Sublime Text 2/3 Packages directory:
git clone https://github.com/foxxyz/sublime_alphpetize.git Alphpetize
Grab the source from Github, copy the whole directory into the Packages directory and rename it to "Alphpetize".
- OSX:
~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
- Linux:
~/.Sublime\ Text\ 2/Packages/
or~/.config/sublime-text-2/Packages/
- Windows:
%APPDATA%/Sublime Text 2/Packages/
The locations for Sublime Text 3 should be identical, disregarding the version number change. The plugin should be picked up automatically. If not, restart Sublime Text.
After installation, select Sort Methods
from the Edit
menu.
Consider the following file:
class Test {
private function bottom() {
}
/**
* This function rocks
* @return void
*/
public function middle() {
}
public function atTheTop() {
}
protected function leaveMe() {
}
}
After running Alphpetize, it should look at follows:
class Test {
public function atTheTop() {
}
/**
* This function rocks
* @return void
*/
public function middle() {
}
protected function leaveMe() {
}
private function bottom() {
}
}
And yes, Alphpetize can also handle files with multiple class definitions.
Static methods are placed at the top of their visibility group.
DocBlocks and single //
-style comments preceding their functions will be preserved during sorting.
Methods defined inside of traits and interfaces are also sorted.
Anything else found floating in-between function definitions will be collected at the top of the class.
Tests can be run using the nice UnitTesting plugin in Package Control.