| Conditions | 17 |
| Paths | 40 |
| Total Lines | 58 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 95 | protected function buildApp(string $app, array $list = [], string $rootNamespace = 'app'): void |
||
| 96 | { |
||
| 97 | if (!is_dir($this->basePath . $app)) { |
||
| 98 | // 创建应用目录 |
||
| 99 | mkdir($this->basePath . $app); |
||
| 100 | } |
||
| 101 | |||
| 102 | $appPath = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : ''); |
||
| 103 | $namespace = $rootNamespace . ($app ? '\\' . $app : ''); |
||
| 104 | |||
| 105 | // 创建配置文件和公共文件 |
||
| 106 | $this->buildCommon($app); |
||
| 107 | // 创建模块的默认页面 |
||
| 108 | $this->buildHello($app, $namespace); |
||
| 109 | |||
| 110 | foreach ($list as $path => $file) { |
||
| 111 | if ('__dir__' == $path) { |
||
| 112 | // 生成子目录 |
||
| 113 | foreach ($file as $dir) { |
||
| 114 | $this->checkDirBuild($appPath . $dir); |
||
| 115 | } |
||
| 116 | } elseif ('__file__' == $path) { |
||
| 117 | // 生成(空白)文件 |
||
| 118 | foreach ($file as $name) { |
||
| 119 | if (!is_file($appPath . $name)) { |
||
| 120 | file_put_contents($appPath . $name, 'php' == pathinfo($name, PATHINFO_EXTENSION) ? "<?php\n" : ''); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } else { |
||
| 124 | // 生成相关MVC文件 |
||
| 125 | foreach ($file as $val) { |
||
| 126 | $val = trim($val); |
||
| 127 | $filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . '.php'; |
||
| 128 | $space = $namespace . '\\' . $path; |
||
| 129 | $class = $val; |
||
| 130 | switch ($path) { |
||
| 131 | case 'controller': // 控制器 |
||
|
1 ignored issue
–
show
|
|||
| 132 | if ($this->app->config->get('route.controller_suffix')) { |
||
|
1 ignored issue
–
show
|
|||
| 133 | $filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . 'Controller.php'; |
||
| 134 | $class = $val . 'Controller'; |
||
| 135 | } |
||
|
1 ignored issue
–
show
|
|||
| 136 | $content = "<?php\nnamespace {$space};\n\nuse think\Controller;\n\nclass {$class} extends Controller\n{\n\n}"; |
||
| 137 | break; |
||
| 138 | case 'model': // 模型 |
||
|
1 ignored issue
–
show
|
|||
| 139 | $content = "<?php\nnamespace {$space};\n\nuse think\Model;\n\nclass {$class} extends Model\n{\n\n}"; |
||
| 140 | break; |
||
| 141 | case 'view': // 视图 |
||
|
1 ignored issue
–
show
|
|||
| 142 | $filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . '.html'; |
||
| 143 | $this->checkDirBuild(dirname($filename)); |
||
| 144 | $content = ''; |
||
| 145 | break; |
||
| 146 | default: |
||
|
1 ignored issue
–
show
|
|||
| 147 | // 其他文件 |
||
| 148 | $content = "<?php\nnamespace {$space};\n\nclass {$class}\n{\n\n}"; |
||
| 149 | } |
||
| 150 | |||
| 151 | if (!is_file($filename)) { |
||
| 152 | file_put_contents($filename, $content); |
||
| 153 | } |
||
| 207 |