| Conditions | 12 |
| Paths | 144 |
| Total Lines | 41 |
| Code Lines | 22 |
| 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 |
||
| 111 | private function parseTemplate(string $template): string |
||
| 112 | { |
||
| 113 | if (empty($this->config['view_path'])) { |
||
| 114 | $this->config['view_path'] = $this->app->getAppPath() . 'view' . DIRECTORY_SEPARATOR; |
||
| 115 | } |
||
| 116 | |||
| 117 | $request = $this->app['request']; |
||
| 118 | |||
| 119 | // 获取视图根目录 |
||
| 120 | if (strpos($template, '@')) { |
||
| 121 | // 跨模块调用 |
||
| 122 | list($app, $template) = explode('@', $template); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($this->config['view_base']) { |
||
| 126 | // 基础视图目录 |
||
| 127 | $app = isset($app) ? $app : $request->app(); |
||
| 128 | $path = $this->config['view_base'] . ($app ? $app . DIRECTORY_SEPARATOR : ''); |
||
| 129 | } else { |
||
| 130 | $path = isset($app) ? $this->app->getBasePath() . $app . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR : $this->config['view_path']; |
||
| 131 | } |
||
| 132 | |||
| 133 | $depr = $this->config['view_depr']; |
||
| 134 | |||
| 135 | if (0 !== strpos($template, '/')) { |
||
| 136 | $template = str_replace(['/', ':'], $depr, $template); |
||
| 137 | $controller = App::parseName($request->controller()); |
||
| 138 | |||
| 139 | if ($controller) { |
||
| 140 | if ('' == $template) { |
||
| 141 | // 如果模板文件名为空 按照默认规则定位 |
||
| 142 | $template = str_replace('.', DIRECTORY_SEPARATOR, $controller) . $depr . (1 == $this->config['auto_rule'] ? App::parseName($request->action(true)) : $request->action()); |
||
| 143 | } elseif (false === strpos($template, $depr)) { |
||
| 144 | $template = str_replace('.', DIRECTORY_SEPARATOR, $controller) . $depr . $template; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } else { |
||
| 148 | $template = str_replace(['/', ':'], $depr, substr($template, 1)); |
||
| 149 | } |
||
| 150 | |||
| 151 | return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.'); |
||
| 152 | } |
||
| 176 |