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.

IncludeCompiler::compile()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 49
Code Lines 33

Duplication

Lines 13
Ratio 26.53 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 49
rs 8.5906
cc 6
eloc 33
nc 9
nop 2
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace TwigJs\Compiler;
20
21
use TwigJs\JsCompiler;
22
use TwigJs\TypeCompilerInterface;
23
24
class IncludeCompiler implements TypeCompilerInterface
25
{
26
    public function getType()
27
    {
28
        return 'Twig_Node_Include';
29
    }
30
31
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
32
    {
33
        if (!$node instanceof \Twig_Node_Include) {
34
            throw new \RuntimeException(
35
                sprintf(
36
                    '$node must be an instanceof of \Include, but got "%s".',
37
                    get_class($node)
38
                )
39
            );
40
        }
41
42
        $compiler->addDebugInfo($node);
43
44
        $compiler->isTemplateName = true;
45 View Code Duplication
        if ($node->getNode('expr') instanceof Twig_Node_Expression_Constant) {
0 ignored issues
show
Bug introduced by
The class TwigJs\Compiler\Twig_Node_Expression_Constant does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

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...
46
            $compiler
47
                ->write("(new ")
48
                ->subcompile($node->getNode('expr'))
49
                ->raw("(this.env_)).render_(sb, ")
50
            ;
51
        } else {
52
            $compiler
53
                ->write("(new ")
54
                ->subcompile($node->getNode('expr'))
55
                ->raw("(this.env_)).render_(sb, ")
56
            ;
57
        }
58
        $compiler->isTemplateName = false;
59
60
        if (false === $node->getAttribute('only')) {
61
            if (!$this->hasVariablesNode($node)) {
62
                $compiler->raw('context');
63
            } else {
64
                $compiler
65
                    ->raw('twig.extend({}, context, ')
66
                    ->subcompile($node->getNode('variables'))
67
                    ->raw(')')
68
                ;
69
            }
70
        } else {
71
            if (!$node->hasNode('variables')) {
72
                $compiler->raw('{}');
73
            } else {
74
                $compiler->subcompile($node->getNode('variables'));
75
            }
76
        }
77
78
        $compiler->raw(");\n");
79
    }
80
81 View Code Duplication
    private function hasVariablesNode(\Twig_NodeInterface $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
82
    {
83
        if (!$node->hasNode('variables')) {
84
            return false;
85
        }
86
87
        if (null === $node->getNode('variables')) {
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...
88
            return false;
89
        }
90
91
        return true;
92
    }
93
}
94