| Conditions | 10 |
| Paths | 24 |
| Total Lines | 94 |
| Code Lines | 59 |
| 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 | protected function compileConstructor(JsCompiler $compiler, \Twig_NodeInterface $node) |
||
| 93 | { |
||
| 94 | $compiler->raw("\n"); |
||
| 95 | |||
| 96 | $countTraits = count($node->getNode('traits')); |
||
| 97 | if ($countTraits) { |
||
| 98 | // traits |
||
| 99 | foreach ($node->getNode('traits') as $i => $trait) { |
||
| 100 | $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('trait_%s', $i)); |
||
| 101 | |||
| 102 | $compiler |
||
| 103 | ->addDebugInfo($trait->getNode('template')) |
||
| 104 | ->write(sprintf("if (!trait_%s.isTraitable()) {\n", $i)) |
||
| 105 | ->indent() |
||
| 106 | ->write( |
||
| 107 | "throw Error('Template \"' + trait_".$i.".getTemplateName() + " . |
||
| 108 | "'\" cannot be used as a trait.');\n" |
||
| 109 | )->outdent() |
||
| 110 | ->write("}\n") |
||
| 111 | ->write(sprintf("var trait_%s_blocks = trait_%s.getBlocks();\n\n", $i, $i)) |
||
| 112 | ; |
||
| 113 | |||
| 114 | foreach ($trait->getNode('targets') as $key => $value) { |
||
| 115 | $compiler |
||
| 116 | ->write(sprintf("trait_%s_blocks[", $i)) |
||
| 117 | ->subcompile($value) |
||
| 118 | ->raw(sprintf("] = trait_%s_blocks[", $i)) |
||
| 119 | ->string($key) |
||
| 120 | ->raw(sprintf("]; delete trait_%s_blocks[", $i)) |
||
| 121 | ->string($key) |
||
| 122 | ->raw("];\n\n") |
||
| 123 | ; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | $compiler |
||
| 128 | ->write("var traits = twig.extend({},\n") |
||
| 129 | ->indent() |
||
| 130 | ; |
||
| 131 | |||
| 132 | for ($i = 0; $i < $countTraits; $i++) { |
||
| 133 | $compiler |
||
| 134 | ->write(sprintf("trait_%s_blocks".($i == $countTraits - 1 ? '' : ',')."\n", $i)) |
||
| 135 | ; |
||
| 136 | } |
||
| 137 | |||
| 138 | $compiler |
||
| 139 | ->outdent() |
||
| 140 | ->write(");\n") |
||
| 141 | ->write("this.setTraits(traits);\n\n") |
||
| 142 | ; |
||
| 143 | |||
| 144 | $compiler |
||
| 145 | ->write("this.setBlocks(twig.extend({}, traits, {\n") |
||
| 146 | ; |
||
| 147 | } else { |
||
| 148 | $compiler |
||
| 149 | ->write("this.setBlocks({\n") |
||
| 150 | ; |
||
| 151 | } |
||
| 152 | |||
| 153 | // blocks |
||
| 154 | $compiler |
||
| 155 | ->indent() |
||
| 156 | ; |
||
| 157 | |||
| 158 | $first = true; |
||
| 159 | foreach ($node->getNode('blocks') as $name => $node) { |
||
| 160 | if (!$first) { |
||
| 161 | $compiler->raw(",\n"); |
||
| 162 | } |
||
| 163 | $first = false; |
||
| 164 | |||
| 165 | $compiler |
||
| 166 | ->write(sprintf("'%s': twig.bind(this.block_%s, this)", $name, $name)) |
||
| 167 | ; |
||
| 168 | } |
||
| 169 | |||
| 170 | if (!$first) { |
||
| 171 | $compiler->raw("\n"); |
||
| 172 | } |
||
| 173 | |||
| 174 | if ($countTraits) { |
||
| 175 | $compiler |
||
| 176 | ->outdent() |
||
| 177 | ->write("}));\n") |
||
| 178 | ; |
||
| 179 | } else { |
||
| 180 | $compiler |
||
| 181 | ->outdent() |
||
| 182 | ->write("});\n") |
||
| 183 | ; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 294 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.