Substitute driven refactoring

If you ever find yourself renaming a core class of the application you should think about speed up the process. In case when class name or method name is unique - Substitute is dominating IDE refactoring tools.

Running sever find/sed commands in console will cover everything except files renaming of course. Be very attentive and figure out all possible variants of name (CamelCase, under_score, plural/singular form). In order to not touch plural form while working with singular form start from plural form first.

# Rename classes like OldClassNamesController
find ./path -type f -exec sed -i 's/OldClassNames/NewClassNames/g'
find ./path -type f -exec sed 's/OldClassName/NewClassName/g'
find ./path -type f -exec sed 's/old_class_names/new_class_names/g'
find ./path -type f -exec sed 's/new_class_name/new_class_name/g'

The thing left rename related files and directories.
for filename in $(find -name $old_name*)
echo $filename;
w_o_ext=$(echo $filename | sed 's/$old_name/$new_name/g');
echo $w_o_ext;
mv $filename $w_o_ext;

Before you commit:
  • Check that database doesn't store any Class name that is under renaming. Apply migration in "Yes" case.
  • Check for super-meta calls where class name or method name is constructed dynamically(you didn't do that, right?)
  • Run your unit tests(you have some, yeah?) and check core pages before commit.
  • Check diff with your version control system