RuleTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 116
Duplicated Lines 12.07 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 14
loc 116
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetIntPropertyReturnsValueOfTypeInteger() 7 7 1
A testGetBooleanPropertyReturnsTrueForStringValue1() 0 7 1
A testGetBooleanPropertyReturnsTrueForStringValueOn() 0 7 1
A testGetBooleanPropertyReturnsTrueForStringValueTrue() 0 7 1
A testGetBooleanPropertyReturnsTrueForDifferentStringValue() 0 7 1
A testGetIntPropertyThrowsExceptionWhenNoPropertyForNameExists() 0 5 1
A testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists() 0 5 1
A testGetStringPropertyThrowsExceptionWhenNoPropertyForNameExists() 0 5 1
A testGetStringPropertyReturnsString() 7 7 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
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD;
19
20
/**
21
 * Test case for the {@link \PHPMD\AbstractRule} class.
22
 *
23
 * @covers \PHPMD\AbstractRule
24
 */
25
class RuleTest extends AbstractTest
26
{
27
    /**
28
     * testGetIntPropertyReturnsValueOfTypeInteger
29
     *
30
     * @return void
31
     */
32 View Code Duplication
    public function testGetIntPropertyReturnsValueOfTypeInteger()
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
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
35
        $rule->addProperty(__FUNCTION__, '42.3');
36
37
        $this->assertSame(42, $rule->getIntProperty(__FUNCTION__));
38
    }
39
40
    /**
41
     * testGetBooleanPropertyReturnsTrueForStringValue1
42
     *
43
     * @return void
44
     */
45
    public function testGetBooleanPropertyReturnsTrueForStringValue1()
46
    {
47
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
48
        $rule->addProperty(__FUNCTION__, '1');
49
50
        $this->assertTrue($rule->getBooleanProperty(__FUNCTION__));
51
    }
52
53
    /**
54
     * testGetBooleanPropertyReturnsTrueForStringValueOn
55
     *
56
     * @return void
57
     */
58
    public function testGetBooleanPropertyReturnsTrueForStringValueOn()
59
    {
60
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
61
        $rule->addProperty(__FUNCTION__, 'on');
62
63
        $this->assertTrue($rule->getBooleanProperty(__FUNCTION__));
64
    }
65
66
    /**
67
     * testGetBooleanPropertyReturnsTrueForStringValueTrue
68
     *
69
     * @return void
70
     */
71
    public function testGetBooleanPropertyReturnsTrueForStringValueTrue()
72
    {
73
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
74
        $rule->addProperty(__FUNCTION__, 'true');
75
76
        $this->assertTrue($rule->getBooleanProperty(__FUNCTION__));
77
    }
78
79
    /**
80
     * testGetBooleanPropertyReturnsTrueForDifferentStringValue
81
     *
82
     * @return void
83
     */
84
    public function testGetBooleanPropertyReturnsTrueForDifferentStringValue()
85
    {
86
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
87
        $rule->addProperty(__FUNCTION__, 'True');
88
89
        $this->assertFalse($rule->getBooleanProperty(__FUNCTION__));
90
    }
91
92
    /**
93
     * testGetIntPropertyThrowsExceptionWhenNoPropertyForNameExists
94
     *
95
     * @return void
96
     * @expectedException \OutOfBoundsException
97
     */
98
    public function testGetIntPropertyThrowsExceptionWhenNoPropertyForNameExists()
99
    {
100
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
101
        $rule->getIntProperty(__FUNCTION__);
102
    }
103
104
    /**
105
     * testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists
106
     *
107
     * @return void
108
     * @expectedException \OutOfBoundsException
109
     */
110
    public function testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists()
111
    {
112
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
113
        $rule->getBooleanProperty(__FUNCTION__);
114
    }
115
116
    /**
117
     * testStringPropertyThrowsExceptionWhenNoPropertyForNameExists
118
     *
119
     * @return void
120
     * @expectedException \OutOfBoundsException
121
     */
122
    public function testGetStringPropertyThrowsExceptionWhenNoPropertyForNameExists()
123
    {
124
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
125
        $rule->getStringProperty(__FUNCTION__);
126
    }
127
128
    /**
129
     * testGetStringPropertyReturnsStringValue
130
     *
131
     * @return void
132
     */
133 View Code Duplication
    public function testGetStringPropertyReturnsString()
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...
134
    {
135
        $rule = $this->getMockForAbstractClass(\PHPMD\AbstractRule::class);
136
        $rule->addProperty(__FUNCTION__, 'Fourty Two');
137
138
        $this->assertSame('Fourty Two', $rule->getStringProperty(__FUNCTION__));
139
    }
140
}
141