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.

SetCompiler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 18.06 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 3
dl 13
loc 72
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
C compile() 13 62 8

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
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 SetCompiler implements TypeCompilerInterface
25
{
26
    private $count = 0;
27
28
    public function getType()
29
    {
30
        return 'Twig_Node_Set';
31
    }
32
33
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
34
    {
35
        if (!$node instanceof \Twig_Node_Set) {
36
            throw new \RuntimeException(
37
                sprintf(
38
                    '$node must be an instanceof of \Twig_Node_Set, but got "%s".',
39
                    get_class($node)
40
                )
41
            );
42
        }
43
44
        $compiler->addDebugInfo($node);
45
46
        if (count($node->getNode('names')) > 1) {
47
            $values = $node->getNode('values');
48
49
            foreach ($node->getNode('names') as $idx => $subNode) {
50
                $compiler
51
                    ->subcompile($subNode)
52
                    ->raw(' = ')
53
                    ->subcompile($values->getNode($idx))
54
                    ->raw(";\n")
55
                ;
56
            }
57
58
            return;
59
        }
60
61
        $count = $this->count++;
62
        $captureStringBuffer = 'cSb'.($count > 0 ? $count : '');
63
        if ($node->getAttribute('capture')) {
64
            $compiler
65
                ->write("var $captureStringBuffer = sb;\n")
66
                ->write("sb = new twig.StringBuffer;")
67
                ->subcompile($node->getNode('values'))
68
            ;
69
        }
70
71
        $compiler->subcompile($node->getNode('names'), false);
72
73
        if ($node->getAttribute('capture')) {
74
            $compiler
75
                ->raw(" = new twig.Markup(sb.toString());\n")
76
                ->write("sb = $captureStringBuffer")
77
            ;
78 View Code Duplication
        } else {
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...
79
            $compiler->raw(' = ');
80
81
            if ($node->getAttribute('safe')) {
82
                $compiler
83
                    ->raw("new twig.Markup(")
84
                    ->subcompile($node->getNode('values'))
85
                    ->raw(")")
86
                ;
87
            } else {
88
                $compiler->subcompile($node->getNode('values'));
89
            }
90
        }
91
92
        $compiler->raw(";\n");
93
        $this->count = $count;
94
    }
95
}
96