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.

ForLoopCompiler::compile()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 55
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 55
rs 8.7752
cc 5
eloc 41
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
namespace TwigJs\Compiler;
4
5
use TwigJs\JsCompiler;
6
use TwigJs\TypeCompilerInterface;
7
8
class ForLoopCompiler implements TypeCompilerInterface
9
{
10
    public function getType()
11
    {
12
        return 'Twig_Node_ForLoop';
13
    }
14
15
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
16
    {
17
        if (!$node instanceof \Twig_Node_ForLoop) {
18
            throw new \RuntimeException(
19
                sprintf(
20
                    '$node must be an instanceof of \Twig_Node_ForLoop, but got "%s".',
21
                    get_class($node)
22
                )
23
            );
24
        }
25
26
        if ($node->getAttribute('else')) {
27
            $compiler
28
                ->write("")
29
                ->subcompile(new \Twig_Node_Expression_Name('_iterated', $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...
30
                ->raw(" = true;\n")
31
            ;
32
        }
33
34
        if ($node->getAttribute('with_loop')) {
35
            $compiler
36
                ->write("++")
37
                ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
38
                ->raw("['index0'];\n")
39
                ->write("++")
40
                ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
41
                ->raw("['index'];\n")
42
                ->write("")
43
                ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
44
                ->raw("['first'] = false;\n")
45
            ;
46
47
            if (!$node->getAttribute('ifexpr')) {
48
                $compiler
49
                    ->write("if (")
50
                    ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
51
                    ->raw("['length']) {\n")
52
                    ->indent()
53
                    ->write("--")
54
                    ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
55
                    ->raw("['revindex0'];\n")
56
                    ->write("--")
57
                    ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
58
                    ->raw("['revindex'];\n")
59
                    ->write("")
60
                    ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
61
                    ->raw("['last'] = 0 === ")
62
                    ->subcompile(new \Twig_Node_Expression_Name('loop', $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...
63
                    ->raw("['revindex0'];\n")
64
                    ->outdent()
65
                    ->write("}\n")
66
                ;
67
            }
68
        }
69
    }
70
}
71