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 |
||
21 | class NotFoundExceptionTests extends TestCase |
||
22 | { |
||
23 | /** |
||
24 | * Test class. |
||
25 | */ |
||
26 | public function testClass() |
||
33 | |||
34 | /** |
||
35 | * Test nameOfMessage method. |
||
36 | */ |
||
37 | public function testNameOfMessage() |
||
51 | |||
52 | /** |
||
53 | * Test handlerMethodNameForObject method. |
||
54 | */ |
||
55 | View Code Duplication | public function testMethodNameForObject() |
|
66 | |||
67 | /** |
||
68 | * Test handlerFor method. |
||
69 | */ |
||
70 | View Code Duplication | public function testHandlerFor() |
|
81 | |||
82 | /** |
||
83 | * Test middlewareOfType method. |
||
84 | */ |
||
85 | View Code Duplication | public function testMiddlewareOfType() |
|
96 | |||
97 | /** |
||
98 | * Test nameOfCommand method. |
||
99 | */ |
||
100 | View Code Duplication | public function testNameOfCommand() |
|
111 | |||
112 | /** |
||
113 | * Test nameOfQuery method. |
||
114 | */ |
||
115 | View Code Duplication | public function testNameOfQuery() |
|
126 | |||
127 | /** |
||
128 | * Test methodForObject method. |
||
129 | */ |
||
130 | View Code Duplication | public function testMethodForObject() |
|
141 | } |
||
142 |
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.