Conditions | 25 |
Paths | > 20000 |
Total Lines | 82 |
Code Lines | 49 |
Lines | 16 |
Ratio | 19.51 % |
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 |
||
88 | public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
||
89 | { |
||
90 | $params = $compiler->getCompiledParams($params); |
||
91 | $tpl = $compiler->getTemplateSource($params['tplPointer']); |
||
92 | |||
93 | // assigns params |
||
94 | $src = $params['from']; |
||
95 | $name = $params['name']; |
||
96 | |||
97 | // evaluates which global variables have to be computed |
||
98 | $varName = '$dwoo.loop.' . trim($name, '"\'') . '.'; |
||
99 | $shortVarName = '$.loop.' . trim($name, '"\'') . '.'; |
||
100 | $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
||
101 | $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
||
102 | $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
||
103 | $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
||
104 | $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
||
105 | $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
||
106 | $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
||
107 | |||
108 | View Code Duplication | if (strpos($name, '$this->scope[') !== false) { |
|
109 | $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
||
110 | } |
||
111 | |||
112 | // gets foreach id |
||
113 | $cnt = self::$cnt ++; |
||
114 | |||
115 | // builds pre processing output |
||
116 | $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';'; |
||
117 | // adds foreach properties |
||
118 | View Code Duplication | if ($usesAny) { |
|
119 | $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n("; |
||
120 | if ($usesIndex) { |
||
121 | $pre .= "\n\t" . '"index" => 0,'; |
||
122 | } |
||
123 | if ($usesIteration) { |
||
124 | $pre .= "\n\t" . '"iteration" => 1,'; |
||
125 | } |
||
126 | if ($usesFirst) { |
||
127 | $pre .= "\n\t" . '"first" => null,'; |
||
128 | } |
||
129 | if ($usesLast) { |
||
130 | $pre .= "\n\t" . '"last" => null,'; |
||
131 | } |
||
132 | if ($usesShow) { |
||
133 | $pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),'; |
||
134 | } |
||
135 | if ($usesTotal) { |
||
136 | $pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),'; |
||
137 | } |
||
138 | $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];'; |
||
139 | } |
||
140 | // checks if the loop must be looped |
||
141 | $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
||
142 | // iterates over keys |
||
143 | $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{"; |
||
144 | // updates properties |
||
145 | if ($usesFirst) { |
||
146 | $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);'; |
||
147 | } |
||
148 | View Code Duplication | if ($usesLast) { |
|
149 | $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);'; |
||
150 | } |
||
151 | $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE; |
||
152 | |||
153 | // build post processing output and cache it |
||
154 | $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);'; |
||
155 | // update properties |
||
156 | if ($usesIndex) { |
||
157 | $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;'; |
||
158 | } |
||
159 | if ($usesIteration) { |
||
160 | $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;'; |
||
161 | } |
||
162 | // end loop |
||
163 | $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
||
164 | if (isset($params['hasElse'])) { |
||
165 | $post .= $params['hasElse']; |
||
166 | } |
||
167 | |||
168 | return $pre . $content . $post; |
||
169 | } |
||
170 | } |
||
171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.