ConstructorNewOperatorTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 43.24 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 6
c 4
b 0
f 2
lcom 1
cbo 2
dl 32
loc 74
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithNewOperator() 8 8 1
A testConstructorWithNewAllowedClassName() 8 8 1
A testConstructorWithoutNewOperator() 0 8 1
A testMethodWithNewOperator() 8 8 1
A testMethodWithNamespaceNewOperator() 8 8 1
A getRule() 0 8 1

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
namespace MS\PHPMD\Tests\Unit\Symfony2;
4
5
use MS\PHPMD\Rule\Symfony2\ConstructorNewOperator;
6
use MS\PHPMD\Tests\Unit\AbstractApplyTest;
7
8
/**
9
 * Class ConstructorNewOperatorTest
10
 *
11
 * @package MS\PHPMD\Tests\Unit\Symfony2
12
 */
13
class ConstructorNewOperatorTest extends AbstractApplyTest
14
{
15
    /**
16
     * @covers MS\PHPMD\Rule\Symfony2\ConstructorNewOperator
17
     */
18 View Code Duplication
    public function testConstructorWithNewOperator()
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...
19
    {
20
        $node = $this->getMethodNode('TestService', '__construct', [
21
            'ClassReference' => array_fill(0, 1, $this->getNode('Reader'))
22
        ]);
23
24
        $this->assertRule($node, 1);
25
    }
26
27
    /**
28
     * @covers MS\PHPMD\Rule\Symfony2\ConstructorNewOperator
29
     */
30 View Code Duplication
    public function testConstructorWithNewAllowedClassName()
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...
31
    {
32
        $node = $this->getMethodNode('TestService', '__construct', [
33
            'ClassReference' => array_fill(0, 1, $this->getNode('\DateTime'))
34
        ]);
35
36
        $this->assertRule($node, 0);
37
    }
38
39
    /**
40
     * @covers MS\PHPMD\Rule\Symfony2\ConstructorNewOperator
41
     */
42
    public function testConstructorWithoutNewOperator()
43
    {
44
        $node = $this->getMethodNode('TestService', '__construct', [
45
            'ClassReference' => []
46
        ]);
47
48
        $this->assertRule($node, 0);
49
    }
50
51
    /**
52
     * @covers MS\PHPMD\Rule\Symfony2\ConstructorNewOperator
53
     */
54 View Code Duplication
    public function testMethodWithNewOperator()
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...
55
    {
56
        $node = $this->getMethodNode('TestService', 'doThings', [
57
            'ClassReference' => array_fill(0, 1, $this->getNode('Reader'))
58
        ]);
59
60
        $this->assertRule($node, 0);
61
    }
62
63
    /**
64
     * @covers MS\PHPMD\Rule\Symfony2\ConstructorNewOperator
65
     */
66 View Code Duplication
    public function testMethodWithNamespaceNewOperator()
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...
67
    {
68
        $node = $this->getMethodNode('TestService', 'doThings', [
69
            'ClassReference' => array_fill(0, 1, $this->getNode('Doctrine\ArrayCollection'))
70
        ]);
71
72
        $this->assertRule($node, 0);
73
    }
74
75
    /**
76
     * @return ConstructorNewOperator
77
     */
78
    protected function getRule()
79
    {
80
        $rule = new ConstructorNewOperator();
81
        $rule->addProperty('delimiter', ',');
82
        $rule->addProperty('allowedClassNames', '\DateTime,ArrayCollection');
83
84
        return $rule;
85
    }
86
}
87