我正在玩重构PHP类.我的原始类有一个构造函数和一个大型方法,它通过各种操作运行字符串并在结尾处吐出结果.
class String
{
public function __contstruct()
{
// a couple of initialisation things
}
public function make($string)
{
// very large method that does lots of different types of filtering to an input string
}
}
Run Code Online (Sandbox Code Playgroud)
我的类通过scrutinizer-ci运行,其中一个建议是使用Composer方法模式将大方法重构为较小的自包含方法.
https://scrutinizer-ci.com/docs/refactorings/compose-method
我做了这个,看起来更整洁,但这是我的问题/查询......
我的新课程现在看起来像这样
class String
{
public function __construct()
{
// a couple of initialisation things
}
public function make($string)
{
$string = $this->smallMethodOne($string);
$string = $this->smallMethodTwo($string);
$string = $this->smallMethodThree($string);
$string = $this->smallMethodFour($string);
$string = $this->smallMethodFive($string);
}
private function smallMethodOne($string) {
// …Run Code Online (Sandbox Code Playgroud)