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 |
||
10 | View Code Duplication | class StockistsCountryReports_WithoutCountry extends SS_Report |
|
|
|||
11 | { |
||
12 | |||
13 | /** |
||
14 | * The class of object being managed by this report. |
||
15 | * Set by overriding in your subclass. |
||
16 | */ |
||
17 | protected $dataClass = 'StockistCountryPage'; |
||
18 | |||
19 | /** |
||
20 | * |
||
21 | * @return String |
||
22 | */ |
||
23 | public function title() |
||
27 | |||
28 | /** |
||
29 | * not sure if this is used in SS3 |
||
30 | * @return String |
||
31 | */ |
||
32 | public function group() |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @return INT - for sorting reports |
||
40 | */ |
||
41 | public function sort() |
||
45 | |||
46 | /** |
||
47 | * working out the items |
||
48 | * @return DataList |
||
49 | */ |
||
50 | public function sourceRecords($params = null) |
||
54 | |||
55 | /** |
||
56 | * @return Array |
||
57 | */ |
||
58 | public function columns() |
||
67 | |||
68 | /** |
||
69 | * |
||
70 | * @return FieldList |
||
71 | */ |
||
72 | public function getParameterFields() |
||
76 | } |
||
77 |
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.