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 |
||
8 | class Workbook |
||
9 | { |
||
10 | /** |
||
11 | * @var int |
||
12 | */ |
||
13 | private $printTitleStart; |
||
14 | |||
15 | /** |
||
16 | * @var int |
||
17 | */ |
||
18 | private $printTitleEnd; |
||
19 | |||
20 | /** |
||
21 | * Set the range of rows to repeat when printing the excel file. |
||
22 | * $startRow=1 and $endRow=1 will repeat the first row only. |
||
23 | * |
||
24 | * @param int $startRow |
||
25 | * @param int $endRow |
||
26 | */ |
||
27 | public function setPrintTitleRange($startRow, $endRow) |
||
34 | |||
35 | /** |
||
36 | * @param array $sheetIds |
||
37 | * @return string |
||
38 | */ |
||
39 | public function getWorkbookXml(array $sheetIds) |
||
46 | |||
47 | /** |
||
48 | * @param array $sheetIds |
||
49 | * @return string |
||
50 | */ |
||
51 | View Code Duplication | public function getWorkbookRelsXml($sheetIds) |
|
60 | |||
61 | /** |
||
62 | * @param array $sheetIds |
||
63 | * @return string |
||
64 | */ |
||
65 | View Code Duplication | private function getSheetsXml($sheetIds) |
|
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | private function getDefinedNamesXml() |
||
91 | } |
||
92 |
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.