| Conditions | 7 |
| Paths | 32 |
| Total Lines | 77 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 144 | protected function visitMixinCall(Mixin $mixin, $name, $blockName, $attributes) |
||
| 145 | { |
||
| 146 | $arguments = $mixin->arguments; |
||
| 147 | $block = $mixin->block; |
||
| 148 | $defaultAttributes = array(); |
||
| 149 | $containsOnlyArrays = true; |
||
| 150 | $arguments = $this->parseMixinArguments($mixin->arguments, $containsOnlyArrays, $defaultAttributes); |
||
| 151 | |||
| 152 | $defaultAttributes = implode(', ', $defaultAttributes); |
||
| 153 | $attributes = $this->parseMixinAttributes($attributes, $defaultAttributes, $mixin->attributes); |
||
| 154 | |||
| 155 | if ($block) { |
||
| 156 | $this->renderClosureOpenning("\\Jade\\Compiler::recordMixinBlock($blockName, ", 'attributes'); |
||
| 157 | $this->visit($block); |
||
| 158 | $this->renderClosureClosing('});'); |
||
| 159 | } |
||
| 160 | |||
| 161 | $strings = array(); |
||
| 162 | $arguments = preg_replace_callback( |
||
| 163 | '#([\'"])(.*(?!<\\\\)(?:\\\\{2})*)\\1#U', |
||
| 164 | function ($match) use (&$strings) { |
||
| 165 | $nextIndex = count($strings); |
||
| 166 | $strings[] = $match[0]; |
||
| 167 | |||
| 168 | return 'stringToReplaceBy' . $nextIndex . 'ThCapture'; |
||
| 169 | }, |
||
| 170 | $arguments |
||
| 171 | ); |
||
| 172 | $arguments = array_map( |
||
| 173 | function ($arg) use ($strings) { |
||
| 174 | return preg_replace_callback( |
||
| 175 | '#stringToReplaceBy([0-9]+)ThCapture#', |
||
| 176 | function ($match) use ($strings) { |
||
| 177 | return $strings[intval($match[1])]; |
||
| 178 | }, |
||
| 179 | $arg |
||
| 180 | ); |
||
| 181 | }, |
||
| 182 | $arguments |
||
| 183 | ); |
||
| 184 | |||
| 185 | array_unshift($arguments, $attributes); |
||
| 186 | $arguments = array_filter($arguments, 'strlen'); |
||
| 187 | $statements = $this->apply('createStatements', $arguments); |
||
| 188 | |||
| 189 | $variables = array_pop($statements); |
||
| 190 | if ($mixin->call && $containsOnlyArrays) { |
||
| 191 | array_splice($variables, 1, 0, array('null')); |
||
| 192 | } |
||
| 193 | $variables = implode(', ', $variables); |
||
| 194 | array_push($statements, $variables); |
||
| 195 | |||
| 196 | $arguments = $statements; |
||
| 197 | |||
| 198 | $paramsPrefix = ''; |
||
| 199 | if (!$this->restrictedScope) { |
||
| 200 | $this->buffer($this->createCode('$__varHandler = get_defined_vars();')); |
||
| 201 | $paramsPrefix = '$__varHandler, '; |
||
| 202 | } |
||
| 203 | $codeFormat = str_repeat('%s;', count($arguments) - 1) . "{$name}({$paramsPrefix}%s)"; |
||
| 204 | |||
| 205 | array_unshift($arguments, $codeFormat); |
||
| 206 | |||
| 207 | $this->buffer($this->apply('createCode', $arguments)); |
||
| 208 | if (!$this->restrictedScope) { |
||
| 209 | $this->buffer( |
||
| 210 | $this->createCode( |
||
| 211 | 'extract(array_diff_key($__varHandler, array(\'__varHandler\' => 1, \'attributes\' => 1)));' |
||
| 212 | ) |
||
| 213 | ); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($block) { |
||
| 217 | $code = $this->createCode("\\Jade\\Compiler::terminateMixinBlock($blockName);"); |
||
| 218 | $this->buffer($code); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 287 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: