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 |
||
11 | class PageRenderMock implements PageRenderInterface, InjectionAwareInterface |
||
12 | { |
||
13 | use InjectionAwareTrait; |
||
14 | |||
15 | |||
16 | 4 | View Code Duplication | public function add($data) |
32 | |||
33 | public function setArray($array, $key) |
||
39 | |||
40 | /** |
||
41 | * Render a standard web page using a specific layout. |
||
42 | */ |
||
43 | 4 | View Code Duplication | public function viewify($views) |
51 | |||
52 | /** |
||
53 | * Render a standard web page using a specific layout. |
||
54 | * |
||
55 | * @param array $data variables to expose to layout view. |
||
56 | * @param integer $status code to use when delivering the result. |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | 3 | public function renderPage($data, $status = 200) |
|
74 | } |
||
75 |
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.