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 | View Code Duplication | class CountInLoopExpressionTest extends AbstractTest |
|
28 | { |
||
29 | /** |
||
30 | * testRuleAppliesToAllTypesOfLoops |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function testRuleAppliesToAllTypesOfLoops() |
||
40 | |||
41 | /** |
||
42 | * testRuleNotApplyToExpressionElsewhere |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | public function testRuleNotApplyToExpressionElsewhere() |
||
52 | |||
53 | /** |
||
54 | * testRuleApplyToNestedLoops |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function testRuleApplyToNestedLoops() |
||
64 | |||
65 | /** |
||
66 | * testMutedRuleAtClassLevel |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | public function testMutedRuleAtClassLevel() |
||
76 | |||
77 | /** |
||
78 | * testMutedRuleAtMethodLevel |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | public function testMutedRuleAtMethodLevel() |
||
88 | } |
||
89 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.