Conditions | 12 |
Paths | 40 |
Total Lines | 50 |
Code Lines | 33 |
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 |
||
123 | private function compile($name, $processInclude, $processExtends) |
||
124 | { |
||
125 | if ($this->routeView) { |
||
126 | $this->routeView = false; |
||
127 | $path = ''; |
||
128 | $stack = debug_backtrace(); |
||
129 | foreach ($stack as $item) { |
||
130 | if (false !== stripos($item['file'], '\\Route\\')) { |
||
131 | $path = pathinfo($item['file'], PATHINFO_DIRNAME) . '/' . $name; |
||
132 | break; |
||
133 | } |
||
134 | } |
||
135 | } else { |
||
136 | $path = $this->packageRoot . '/view/' . $name; |
||
137 | } |
||
138 | |||
139 | if (file_exists($path)) { |
||
140 | ob_start(); |
||
141 | readfile($path); |
||
142 | $code = ob_get_clean(); |
||
143 | } else { |
||
144 | throw new FileNotFoundException($path); |
||
145 | } |
||
146 | |||
147 | if ($processInclude) { |
||
148 | preg_match_all('/<!-- include (.*) -->/', $code, $matchList); |
||
149 | if (count($matchList)) { |
||
150 | foreach ($matchList[1] as $key => $template) { |
||
151 | if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) { |
||
152 | $template = trim($template); |
||
153 | $code = str_replace($matchList[0][$key], $this->compile($template, true, false), $code); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | |||
159 | if ($processExtends) { |
||
160 | preg_match_all('/<!-- extends (.*) -->/', $code, $matchList); |
||
161 | if (isset($matchList[1][0])) { |
||
162 | $template = trim($matchList[1][0]); |
||
163 | $parentHtml = $this->compile($template, true, false); |
||
164 | |||
165 | $code = str_replace($matchList[0][0], '', $code); |
||
166 | $parentHtml = str_replace('<!-- section -->', $code, $parentHtml); |
||
167 | $code = $parentHtml; |
||
168 | } |
||
169 | } |
||
170 | |||
171 | return $code; |
||
172 | } |
||
173 | |||
196 |