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 |
||
27 | class LongClassNameTest extends AbstractTest |
||
28 | { |
||
29 | /** |
||
30 | * Tests that the rule does not apply to class name length (43) below threshold (44) |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function testRuleNotAppliesToClassNameBelowThreshold() |
||
41 | |||
42 | /** |
||
43 | * Tests that the rule applies to class name length (40) below threshold (39) |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | public function testRuleAppliesToClassNameAboveThreshold() |
||
54 | |||
55 | /** |
||
56 | * Tests that the rule does not apply to interface name length (47) below threshold (47) |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function testRuleNotAppliesToInterfaceNameBelowThreshold() |
||
61 | { |
||
62 | $rule = new LongClassName(); |
||
63 | $rule->addProperty('maximum', 47); |
||
64 | $rule->setReport($this->getReportWithNoViolation()); |
||
65 | $rule->apply($this->getInterface()); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Tests that the rule applies to class name length (44) above threshold (43) |
||
70 | * |
||
71 | * @return void |
||
72 | */ |
||
73 | View Code Duplication | public function testRuleAppliesToInterfaceNameAboveThreshold() |
|
74 | { |
||
75 | $rule = new LongClassName(); |
||
76 | $rule->addProperty('maximum', 43); |
||
77 | $rule->setReport($this->getReportWithOneViolation()); |
||
78 | $rule->apply($this->getInterface()); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Tests that the rule does not apply to class name length (69) below threshold (60) |
||
83 | * with configured suffix length (9) |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | public function testRuleNotAppliesToClassNameLengthWithSuffixSubtractedBelowThreshold() |
||
95 | |||
96 | /** |
||
97 | * Tests that the rule applies to class name length (66) above threshold (56) with configured suffix length (9) |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | public function testRuleAppliesToClassNameLengthWithSuffixSubtractedAboveThreshold() |
||
109 | |||
110 | /** |
||
111 | * Tests that the rule does not apply to class name length (55) below threshold (54) |
||
112 | * not matching configured suffix length (9) |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | public function testRuleAppliesToClassNameLengthWithoutSuffixSubtracted() |
||
124 | } |
||
125 |