GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AmdCompiler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 10.39 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 2
dl 8
loc 77
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B compileClassHeader() 8 56 6
A compileClassFooter() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace TwigJs\Compiler\ModuleCompiler;
3
4
use Twig_NodeInterface;
5
use TwigJs\JsCompiler;
6
use TwigJs\Compiler\ModuleCompiler;
7
use TwigJs\TypeCompilerInterface;
8
9
class AmdCompiler extends ModuleCompiler implements TypeCompilerInterface
10
{
11
    /**
12
     * @var boolean
13
     */
14
    private $explicitName;
15
16
    public function __construct($explicitName = true)
17
    {
18
        $this->explicitName = $explicitName;
19
    }
20
21
    protected function compileClassHeader(JsCompiler $compiler, Twig_NodeInterface $node)
22
    {
23
        $this->functionName = $functionName = $compiler->templateFunctionName
24
            = $compiler->getFunctionName($node);
0 ignored issues
show
Compatibility introduced by
$node of type object<Twig_NodeInterface> is not a sub-type of object<Twig_Node_Module>. It seems like you assume a concrete implementation of the interface Twig_NodeInterface to be always present.

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.

Loading history...
25
26
        $parts = explode('.', $functionName);
27
        array_pop($parts);
28
29
        $filename = $node->getAttribute('filename');
30 View Code Duplication
        if (!empty($filename)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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'))) {
0 ignored issues
show
Bug introduced by
The method getNode() does not exist on Twig_NodeInterface. Did you maybe mean getNodeTag()?

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.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
78
    protected function compileClassFooter(JsCompiler $compiler, \Twig_NodeInterface $node)
79
    {
80
        $compiler
81
            ->write("return ".$this->functionName.";\n")
82
            ->outdent()
83
            ->write("});");
84
    }
85
}
86