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.

NameCompiler::compile()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 54
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 54
rs 7.8331
cc 7
eloc 33
nc 7
nop 2

How to fix   Long Method   

Long Method

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:

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\Expression;
20
21
use TwigJs\JsCompiler;
22
use TwigJs\TypeCompilerInterface;
23
24
class NameCompiler implements TypeCompilerInterface
25
{
26
    public function getType()
27
    {
28
        return 'Twig_Node_Expression_Name';
29
    }
30
31
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
32
    {
33
        if (!$node instanceof \Twig_Node_Expression_Name) {
34
            throw new \RuntimeException(
35
                sprintf(
36
                    '$node must be an instanceof of \Expression_Name, but got "%s".',
37
                    get_class($node)
38
                )
39
            );
40
        }
41
42
        $name = $node->getAttribute('name');
43
44
        if ($node->getAttribute('is_defined_test')) {
45
            if ($node->isSpecial()) {
46
                $compiler->repr(true);
47
            } else {
48
                $compiler->raw('(')->repr($name)->raw(' in context)');
49
            }
50
        } elseif ($node->isSpecial()) {
51
            static $specialVars = array(
52
                '_self' => 'this',
53
                '_context' => 'context',
54
                '_charset' => 'this.env_.getCharset()',
55
            );
56
57
            if (!isset($specialVars[$name])) {
58
                throw new \RuntimeException(
59
                    sprintf(
60
                        'The special var "%s" is not supported by the NameCompiler.',
61
                        $name
62
                    )
63
                );
64
            }
65
66
            $compiler->raw($specialVars[$name]);
67
        } else {
68
            if (isset($compiler->localVarMap[$name])) {
69
                $compiler->raw($compiler->localVarMap[$name]);
70
71
                return;
72
            }
73
74
            // FIXME: Add strict behavior?
75
            //        see Template::getContext()
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
            $compiler
77
                ->raw('(')
78
                ->string($name)
79
                ->raw(' in context ? context[')
80
                ->string($name)
81
                ->raw('] : null)')
82
            ;
83
        }
84
    }
85
}
86