Completed
Push — 4.x-fix-nodes ( 1f82a2 )
by Cees-Jan
02:03
created

Element   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 40.63 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 26
loc 64
ccs 0
cts 41
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 26 26 3
A compile() 0 18 3

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
 * This file is part of TwigView.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Lib\Twig\Node;
12
13
/**
14
 * Class Element
15
 * @package WyriHaximus\TwigView\Lib\Twig\Node
16
 */
17
class Element extends \Twig_Node
18
{
19
    /**
20
     * Constructor.
21
     *
22
     * @param \Twig_Node_Expression $name    Name.
23
     * @param \Twig_Node_Expression $data    Data.
24
     * @param \Twig_Node_Expression $options Options.
25
     * @param string                $lineno  Linenumber.
26
     * @param string                $tag     Tag.
27
     */
28 View Code Duplication
    public function __construct(
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...
29
        \Twig_Node_Expression $name,
30
        \Twig_Node_Expression $data = null,
31
        \Twig_Node_Expression $options = null,
32
        $lineno = '',
33
        $tag = null
34
    ) {
35
        if ($data === null) {
36
            $data = new \Twig_Node_Expression_Array([], $lineno);
37
        }
38
39
        if ($options === null) {
40
            $options = new \Twig_Node_Expression_Array([], $lineno);
41
        }
42
43
        parent::__construct(
44
            [
45
                'name' => $name,
46
                'data' => $data,
47
                'options' => $options,
48
            ],
49
            [],
50
            $lineno,
51
            $tag
52
        );
53
    }
54
55
    /**
56
     * Compile node.
57
     *
58
     * @param \Twig_Compiler $compiler Compiler.
59
     *
60
     * @return void
61
     */
62
    public function compile(\Twig_Compiler $compiler)
63
    {
64
        $compiler->addDebugInfo($this);
65
66
        $compiler->raw('echo $context[\'_view\']->element(');
67
        $compiler->subcompile($this->getNode('name'));
68
        $data = $this->getNode('data');
69
        if ($data !== null) {
70
            $compiler->raw(',');
71
            $compiler->subcompile($data);
72
        }
73
        $options = $this->getNode('options');
74
        if ($options !== null) {
75
            $compiler->raw(',');
76
            $compiler->subcompile($options);
77
        }
78
        $compiler->raw(");\n");
79
    }
80
}
81