ShortMethodNameTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 115
Duplicated Lines 54.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 63
loc 115
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testRuleAppliesToFunctionWithNameShorterThanThreshold() 8 8 1
A testRuleNotAppliesToFunctionWithNameEqualToThreshold() 8 8 1
A testRuleNotAppliesToFunctionWithNameLongerThanThreshold() 8 8 1
A testRuleAppliesToMethodWithNameShorterThanThreshold() 8 8 1
A testRuleNotAppliesToMethodWithNameEqualToThreshold() 8 8 1
A testRuleNotAppliesToMethodWithNameLongerThanThreshold() 8 8 1
A testRuleNotAppliesToMethodWithShortNameWhenException() 8 8 1
A testRuleAlsoWorksWithoutExceptionListConfigured() 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\Rule\Naming;
19
20
use PHPMD\AbstractTest;
21
22
/**
23
 * Test case for the very short method and function name rule.
24
 *
25
 * @covers PHPMD\Rule\Naming\ShortMethodName
26
 */
27
class ShortMethodNameTest extends AbstractTest
28
{
29
    /**
30
     * testRuleAppliesToFunctionWithNameShorterThanThreshold
31
     *
32
     * @return void
33
     */
34 View Code Duplication
    public function testRuleAppliesToFunctionWithNameShorterThanThreshold()
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...
35
    {
36
        $rule = new ShortMethodName();
37
        $rule->addProperty('minimum', 54);
38
        $rule->addProperty('exceptions', '');
39
        $rule->setReport($this->getReportMock(1));
40
        $rule->apply($this->getFunction());
41
    }
42
43
    /**
44
     * testRuleNotAppliesToFunctionWithNameEqualToThreshold
45
     *
46
     * @return void
47
     */
48 View Code Duplication
    public function testRuleNotAppliesToFunctionWithNameEqualToThreshold()
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...
49
    {
50
        $rule = new ShortMethodName();
51
        $rule->addProperty('minimum', 52);
52
        $rule->addProperty('exceptions', '');
53
        $rule->setReport($this->getReportMock(0));
54
        $rule->apply($this->getFunction());
55
    }
56
57
    /**
58
     * testRuleNotAppliesToFunctionWithNameLongerThanThreshold
59
     *
60
     * @return void
61
     */
62 View Code Duplication
    public function testRuleNotAppliesToFunctionWithNameLongerThanThreshold()
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...
63
    {
64
        $rule = new ShortMethodName();
65
        $rule->addProperty('minimum', 54);
66
        $rule->addProperty('exceptions', '');
67
        $rule->setReport($this->getReportMock(0));
68
        $rule->apply($this->getFunction());
69
    }
70
    /**
71
     * testRuleAppliesToFunctionWithNameShorterThanThreshold
72
     *
73
     * @return void
74
     */
75 View Code Duplication
    public function testRuleAppliesToMethodWithNameShorterThanThreshold()
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...
76
    {
77
        $rule = new ShortMethodName();
78
        $rule->addProperty('minimum', 52);
79
        $rule->addProperty('exceptions', '');
80
        $rule->setReport($this->getReportMock(1));
81
        $rule->apply($this->getMethod());
82
    }
83
84
    /**
85
     * testRuleNotAppliesToMethodWithNameEqualToThreshold
86
     *
87
     * @return void
88
     */
89 View Code Duplication
    public function testRuleNotAppliesToMethodWithNameEqualToThreshold()
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...
90
    {
91
        $rule = new ShortMethodName();
92
        $rule->addProperty('minimum', 50);
93
        $rule->addProperty('exceptions', '');
94
        $rule->setReport($this->getReportMock(0));
95
        $rule->apply($this->getMethod());
96
    }
97
98
    /**
99
     * testRuleNotAppliesToMethodWithNameLongerThanThreshold
100
     *
101
     * @return void
102
     */
103 View Code Duplication
    public function testRuleNotAppliesToMethodWithNameLongerThanThreshold()
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...
104
    {
105
        $rule = new ShortMethodName();
106
        $rule->addProperty('minimum', 52);
107
        $rule->addProperty('exceptions', '');
108
        $rule->setReport($this->getReportMock(0));
109
        $rule->apply($this->getMethod());
110
    }
111
112
    /**
113
     * testRuleNotAppliesToMethodWithNameLongerThanThreshold
114
     *
115
     * @return void
116
     */
117 View Code Duplication
    public function testRuleNotAppliesToMethodWithShortNameWhenException()
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...
118
    {
119
        $rule = new ShortMethodName();
120
        $rule->addProperty('minimum', 100);
121
        $rule->addProperty('exceptions', 'testRuleNotAppliesToMethodWithShortNameWhenException,another');
122
        $rule->setReport($this->getReportMock(0));
123
        $rule->apply($this->getMethod());
124
    }
125
126
    /**
127
     * testRuleAlsoWorksWithoutExceptionListConfigured
128
     *
129
     * @return void
130
     * @since 2.2.2
131
     * @link https://github.com/phpmd/phpmd/issues/80
132
     * @link https://github.com/phpmd/phpmd/issues/270
133
     */
134 View Code Duplication
    public function testRuleAlsoWorksWithoutExceptionListConfigured()
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...
135
    {
136
        $rule = new ShortMethodName();
137
        $rule->addProperty('minimum', 100);
138
        $rule->setReport($this->getReportMock(0));
139
        $rule->apply($this->getMethodMock());
140
    }
141
}
142