| Conditions | 6 |
| Paths | 8 |
| Total Lines | 56 |
| Code Lines | 41 |
| Lines | 8 |
| Ratio | 14.29 % |
| 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 |
||
| 21 | protected function compileClassHeader(JsCompiler $compiler, Twig_NodeInterface $node) |
||
| 22 | { |
||
| 23 | $this->functionName = $functionName = $compiler->templateFunctionName |
||
| 24 | = $compiler->getFunctionName($node); |
||
|
|
|||
| 25 | |||
| 26 | $parts = explode('.', $functionName); |
||
| 27 | array_pop($parts); |
||
| 28 | |||
| 29 | $filename = $node->getAttribute('filename'); |
||
| 30 | View Code Duplication | if (!empty($filename) |
|
| 31 | && false !== strpos($filename, DIRECTORY_SEPARATOR)) { |
||
| 32 | $parts = explode(DIRECTORY_SEPARATOR, realpath($filename)); |
||
| 33 | $filename = implode(DIRECTORY_SEPARATOR, array_splice($parts, -4)); |
||
| 34 | } |
||
| 35 | |||
| 36 | $compiler |
||
| 37 | ->write("/**\n") |
||
| 38 | ->write(" * @fileoverview Compiled template for file\n") |
||
| 39 | ->write(" *\n") |
||
| 40 | ->write(" * ".str_replace('*/', '*\\/', $filename)."\n") |
||
| 41 | ->write(" *\n") |
||
| 42 | ->write(" * @suppress {checkTypes|fileoverviewTags}\n") |
||
| 43 | ->write(" */\n") |
||
| 44 | ->write("\n") |
||
| 45 | ; |
||
| 46 | |||
| 47 | if ($this->explicitName) { |
||
| 48 | $compiler->write("define('$functionName.twig', ['twig'], function (Twig) {\n"); |
||
| 49 | } else { |
||
| 50 | $compiler->write("define(['twig'], function (Twig) {\n"); |
||
| 51 | } |
||
| 52 | $compiler |
||
| 53 | ->indent() |
||
| 54 | ->write("\n") |
||
| 55 | ->write( |
||
| 56 | "/**\n", |
||
| 57 | " * @constructor\n", |
||
| 58 | " * @param {twig.Environment} env\n", |
||
| 59 | " * @extends {twig.Template}\n", |
||
| 60 | " */\n" |
||
| 61 | ) |
||
| 62 | ->write("$functionName = function (env) {\n") |
||
| 63 | ->indent() |
||
| 64 | ->write("twig.Template.call(this, env);\n") |
||
| 65 | ; |
||
| 66 | |||
| 67 | View Code Duplication | if (count($node->getNode('blocks')) || count($node->getNode('traits'))) { |
|
| 68 | $this->compileConstructor($compiler, $node); |
||
| 69 | } |
||
| 70 | |||
| 71 | $compiler |
||
| 72 | ->outdent() |
||
| 73 | ->write("};\n") |
||
| 74 | ->write("twig.inherits($functionName, twig.Template);\n\n") |
||
| 75 | ; |
||
| 76 | } |
||
| 77 | |||
| 86 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.