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.

GetAttrCompiler::compile()   C
last analyzed

Complexity

Conditions 11
Paths 37

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 5.9999
cc 11
eloc 33
nc 37
nop 2

How to fix   Long Method    Complexity   

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 GetAttrCompiler implements TypeCompilerInterface
25
{
26
    public function getType()
27
    {
28
        return 'Twig_Node_Expression_GetAttr';
29
    }
30
31
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
32
    {
33
        if (!$node instanceof \Twig_Node_Expression_GetAttr) {
34
            throw new \RuntimeException(
35
                sprintf(
36
                    '$node must be an instanceof of \Expression_GetAttr, but got "%s".',
37
                    get_class($node)
38
                )
39
            );
40
        }
41
42
        $compiler->raw('twig.attr(');
43
44
        if ($node->getAttribute('is_defined_test') && $compiler->getEnvironment()->isStrictVariables()) {
45
            $compiler->subcompile(new \Twig_Node_Expression_Filter(
46
                $node->getNode('node'),
47
                new \Twig_Node_Expression_Constant('default', $node->getLine()),
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Node::getLine() has been deprecated with message: since 1.27 (to be removed in 2.0)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
                new \Twig_Node(),
49
                $node->getLine()
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Node::getLine() has been deprecated with message: since 1.27 (to be removed in 2.0)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50
            ));
51
        } else {
52
            $compiler->subcompile($node->getNode('node'));
53
        }
54
55
        $compiler
56
            ->raw(', ')
57
            ->subcompile($node->getNode('attribute'))
58
        ;
59
60
        $defaultArguments = 0 === count($node->getNode('arguments'));
61
        $defaultAccess = \Twig_TemplateInterface::ANY_CALL === $node->getAttribute('type');
62
        $defaultTest = false == $node->getAttribute('is_defined_test');
63
64
        if (!$defaultArguments) {
65
            $compiler->raw(', ')->subcompile($node->getNode('arguments'));
66
        } elseif (!$defaultAccess || !$defaultTest) {
67
            $compiler->raw(', undefined');
68
        }
69
70
        if (!$defaultAccess) {
71
            $compiler->raw(', ')->repr($node->getAttribute('type'));
72
        } elseif (!$defaultTest) {
73
            $compiler->raw(', undefined');
74
        }
75
76
        if (!$defaultTest) {
77
            $compiler->raw(', '.($node->getAttribute('is_defined_test') ?
78
                    'true' : 'false'));
79
        }
80
81
        $compiler->raw(')');
82
    }
83
}
84