Completed
Push — master ( bf375b...cc5661 )
by Rafał
07:07
created

ContainerNodeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 94.57 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 6
dl 87
loc 92
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 10 10 1
A getTests() 67 67 1
A tearDown() 10 10 4

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 the Superdesk Web Publisher Templates System.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\TemplatesSystem\Tests\Twig\Node;
16
17
use SWP\Component\TemplatesSystem\Twig\Node\ContainerNode;
18
19
class ContainerNodeTest extends \Twig_Test_NodeTestCase
20
{
21 View Code Duplication
    public function testConstructor()
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...
22
    {
23
        $name = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]);
24
        $parameters = new \Twig_Node_Expression_Array([], 1);
25
        $body = new \Twig_Node_Text('', 1);
26
        $node = new ContainerNode($name, $parameters, $body, 1, 'gimme');
27
        $this->assertEquals($name, $node->getNode('name'));
28
        $this->assertEquals($parameters, $node->getNode('parameters'));
29
        $this->assertEquals($body, $node->getNode('body'));
30
    }
31
32 View Code Duplication
    public function getTests()
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...
33
    {
34
        $name1 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]);
35
        $parameters1 = new \Twig_Node_Expression_Array([], 1);
36
        $body1 = new \Twig_Node_Text('Test body', 1);
37
        $node1 = new ContainerNode($name1, $parameters1, $body1, 1, 'gimme');
38
39
        $name2 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 2)]);
40
        $body2 = new \Twig_Node_Text('Test body', 2);
41
        $node2 = new ContainerNode($name2, null, $body2, 2, 'gimme');
42
43
        $name3 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 3)]);
44
        $parameters3 = new \Twig_Node_Expression_Array([new \Twig_Node_Expression_Constant('foo', 1), new \Twig_Node_Expression_Constant(true, 1)], 1);
45
        $body3 = new \Twig_Node_Text('Test body', 3);
46
        $node3 = new ContainerNode($name3, $parameters3, $body3, 3, 'gimme');
47
48
        return [
49
            [$node1, <<<'EOF'
50
// line 1
51
$containerService = $this->env->getExtension('swp_container')->getContainerService();
52
$container = $containerService->getContainer("container_name", array());
53
if ($container->isVisible()) {
54
    echo $container->renderOpenTag();
55
    if ($container->hasWidgets()) {
56
        echo $container->renderWidgets();
57
    } else {
58
        echo "Test body";
59
    }
60
    echo $container->renderCloseTag();
61
}
62
unset($container);unset($containerService);
63
EOF
64
            ],
65
            [$node2, <<<'EOF'
66
// line 2
67
$containerService = $this->env->getExtension('swp_container')->getContainerService();
68
$container = $containerService->getContainer("container_name", array());
69
if ($container->isVisible()) {
70
    echo $container->renderOpenTag();
71
    if ($container->hasWidgets()) {
72
        echo $container->renderWidgets();
73
    } else {
74
        echo "Test body";
75
    }
76
    echo $container->renderCloseTag();
77
}
78
unset($container);unset($containerService);
79
EOF
80
            ],
81
            [$node3, <<<'EOF'
82
// line 3
83
$containerService = $this->env->getExtension('swp_container')->getContainerService();
84
$container = $containerService->getContainer("container_name", array("foo" => true));
85
if ($container->isVisible()) {
86
    echo $container->renderOpenTag();
87
    if ($container->hasWidgets()) {
88
        echo $container->renderWidgets();
89
    } else {
90
        echo "Test body";
91
    }
92
    echo $container->renderCloseTag();
93
}
94
unset($container);unset($containerService);
95
EOF
96
            ],
97
        ];
98
    }
99
100 View Code Duplication
    protected function tearDown()
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...
101
    {
102
        $reflection = new \ReflectionObject($this);
103
        foreach ($reflection->getProperties() as $prop) {
104
            if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
0 ignored issues
show
introduced by
Consider using $prop->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
105
                $prop->setAccessible(true);
106
                $prop->setValue($this, null);
107
            }
108
        }
109
    }
110
}
111