Wallogit.com
2017 © Pedro Peláez
"refactool" is short for "refactoring tool". It's a toolset for code refactoring., (*1)
refactool require php5.3 or higher, (*2)
refactool is PSR-0 compliant and can be installed using Composer. Add sandysong/refactool to your composer.json, (*3)
{
"require": {
"sandysong/refactool": "*"
}
}
If you're new to Composer..., (*4)
cd to your the directory where you'll be writing your Commando script and run composer install
Currently installing via Composer is the only supported option., (*5)
You can use bin/rname to do some rename stuff such as: + rename filename to fit PSR-0 standard + rename classname or method name by preg_replace, (*6)
You can type rname --help to see help information, (*7)
songqi@ubuntu:~/work/$ rname --help
/home/songqi/work/refactool/bin/rname
Usage: /home/songqi/work/refactool/bin/rname [OPTIONS] src dest
Change directory structure or class name to fit the standard.
This tool scan src dir for class definations and put them to a new dir, other files are left.
It does not support namespace yet
src
srcRequired. src directory of your code
dest
destRequired. dest directory to generate code
--help
Show the help page for this command.
-i/--input <argument>
Regex to match input files, default is '/\.php$/'
-p/--pattern <argument>
pattern to match your class name or method name
-r/--replace <argument>
replacement to replace your class or method name
-s/--standard <argument>
naming standard, avalible standards are: psr0, yaf_controller
-t/--target <argument>
if you want to rename class or method, specify target here: class, method
Restructure the directory/file name to fit PSR-0 standard, (*8)
$rname /path/to/your/code/source /path/to/put/things/in
Rename all class that match 'Comm_(.*)' to 'Common_$1', (*9)
$rname -t class -p '/Comm_(.*)/' -r 'Common_$1' /path/to/your/code/source /path/to/put/things/in
It will change all class/interface name in: * class/interface defination: class Comm_Foo {} * extends: class Foo extends Comm_Foo {} * implements: class Foo implements Comm_Foo {} * instantiation: $obj = new Comm_Foo(); * static call: $res = Comm_Foo::hello();, (*10)
Rename all method that match 'run' to 'indexAction', (*11)
$rname -t method -p 'run' -r 'indexAction' /path/to/your/code/source /path/to/put/things/in
It will change all method name in: * method defination: public function run() {} * method call: $obj->run(); * static method call: Comm_Foo::run();, (*12)
Rename class/interface and make it match yaf_controller's naming standard, (*13)
$rname -t class -p '/Controller_(.*)/' -r '$1' -s yaf_controller /path/to/your/code/source /path/to/put/things/in
You should find out that php-yaf's controller has another naming standard that not compliant with PSR-0 in this ways:, (*14)
Each part of controller name has first character uppercase and the rest lowercase, (*15)
So this is a right format:, (*16)
Aoo_Boo_CooController
And this is not:, (*17)
AOO_BOO_COOController
Controller's classname must ended with "Controller" but the filename are not:, (*18)
Controller name:, (*19)
Aoo_Boo_CooController
File name:, (*20)
Aoo/Boo/Coo.php
So yaf_controller standard will do this: + when output code to file, rtrim 'Controller' from the classname and then generate the filename and path. + when match and replace class name with regex, strtolower and ucfirst each part of classname and then add 'Controller' to the end of classname., (*21)