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 |
||
13 | abstract class AbstractTest extends TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @param RouteCollection|null $routeCollection |
||
17 | * |
||
18 | * @return Router |
||
19 | */ |
||
20 | protected function getRouter($routeCollection = null) |
||
38 | |||
39 | /** |
||
40 | * @return RouteCollection |
||
41 | */ |
||
42 | protected function getFooRouteCollection() |
||
51 | |||
52 | /** |
||
53 | * @param bool $secure |
||
54 | * @param bool $trailingSlash |
||
55 | * @return Request |
||
56 | */ |
||
57 | View Code Duplication | protected function getFooRequest($secure = true, $trailingSlash = true) |
|
71 | |||
72 | /** |
||
73 | * @param bool $secure |
||
74 | * @param bool $trailingSlash |
||
75 | * @return Request |
||
76 | */ |
||
77 | View Code Duplication | protected function getBazRequest($secure = true, $trailingSlash = true) |
|
91 | |||
92 | /** |
||
93 | * @return array |
||
94 | */ |
||
95 | public function configProvider() |
||
108 | } |
||
109 |
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.