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 |
||
32 | View Code Duplication | class LatestMessageTest extends MessageTestCase |
|
33 | { |
||
34 | |||
35 | /** |
||
36 | * testConstructor |
||
37 | */ |
||
38 | public function testConstructor() |
||
43 | |||
44 | /** |
||
45 | * getClassName must return a string with the FQN of the command class being tested |
||
46 | * @return string |
||
47 | */ |
||
48 | protected function getClassName() |
||
52 | |||
53 | /** |
||
54 | * Must return an array in the format: |
||
55 | * |
||
56 | * [ |
||
57 | * 'name' => 'functionName', // required |
||
58 | * 'with' => [arguments for with] // optional |
||
59 | * 'return' => return value // optional, defaults to return self |
||
60 | * 'times' => number of times it will be invoked |
||
61 | * ] |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | protected function getExpectations() |
||
76 | } |
||
77 |