I have one specific class in my project that have a lot of static and class methods (this is on purpose, it makes more sense, in this case, to use one big class instead of many smaller ones).
The methods were defined using underscore case like method_name instead of PSR-1 compliant methodName and we are converting a bunch of stuff to PSR-1.
Now, we could use something like these methods (below) to allow the usage of either one (method_name and methodName). The advantage is that we do not risk to introduce new bugs and all the current code using it still works, and we can migrate them slowly.
<?php
// enable PSR-1 for class methods
public static function __callStatic($name, $args) {
$toLower = function($c) { return '_'.strtolower($c[1]); };
$underscoreCased = preg_replace_callback('/([A-Z])/', $toLower, $name);
return forward_static_call_array(['ClassName', $underscoreCased], $args);
}
// enable PSR-1 for instance metods
public function __call($name, $args) {
$toLower = function($c) { return '_'.strtolower($c[1]); };
$underscoreCased = preg_replace_callback('/([A-Z])/', $toLower, $name);
return call_user_func_array([$this, $underscoreCased], $args);
}
Now the question, is this too ugly? Should we avoid doing this despite the benefits listed above?