Conditions | 12 |
Paths | 40 |
Total Lines | 50 |
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 |
||
92 | private function compile($name, $processInclude, $processExtends) |
||
93 | { |
||
94 | if ($this->isRouteView) { |
||
95 | $this->isRouteView = false; |
||
96 | $path = ''; |
||
97 | $stack = debug_backtrace(); |
||
98 | foreach ($stack as $item) { |
||
99 | if (false !== stripos($item['file'], DIRECTORY_SEPARATOR . 'Route' . DIRECTORY_SEPARATOR)) { |
||
100 | $path = pathinfo($item['file'], PATHINFO_DIRNAME) . '/' . $name; |
||
101 | break; |
||
102 | } |
||
103 | } |
||
104 | } else { |
||
105 | $path = $this->packageRoot . '/view/' . $name; |
||
106 | } |
||
107 | |||
108 | if (file_exists($path)) { |
||
109 | ob_start(); |
||
110 | readfile($path); |
||
111 | $code = ob_get_clean(); |
||
112 | } else { |
||
113 | throw new FileNotFoundException($path); |
||
114 | } |
||
115 | |||
116 | if ($processInclude) { |
||
117 | preg_match_all('/<!-- include (.*) -->/', $code, $matchList); |
||
118 | if (isset($matchList[1])) { |
||
119 | foreach ($matchList[1] as $key => $template) { |
||
120 | if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) { |
||
121 | $template = trim($template); |
||
122 | $code = str_replace($matchList[0][$key], $this->compile($template, true, false), $code); |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | |||
128 | if ($processExtends) { |
||
129 | preg_match_all('/<!-- extends (.*) -->/', $code, $matchList); |
||
130 | if (isset($matchList[1][0])) { |
||
131 | $template = trim($matchList[1][0]); |
||
132 | $parentHtml = $this->compile($template, true, false); |
||
133 | |||
134 | $code = str_replace($matchList[0][0], '', $code); |
||
135 | $parentHtml = str_replace('<!-- section -->', $code, $parentHtml); |
||
136 | $code = $parentHtml; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | return $code; |
||
141 | } |
||
142 | |||
163 |