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 ContentBlock_ColumnLayout extends ContentBlock |
||
|
|||
9 | { |
||
10 | |||
11 | private static $db = [ |
||
12 | 'Layout' => 'Enum("One Column, Two Column, Three Column")', |
||
13 | 'ColumnOneContent' => 'HTMLText', |
||
14 | 'ColumnTwoContent' => 'HTMLText', |
||
15 | 'ColumnThreeContent' => 'HTMLText', |
||
16 | 'ColumnOneColour' => 'Varchar', |
||
17 | 'ColumnTwoColour' => 'Varchar', |
||
18 | 'ColumnThreeColour' => 'Varchar', |
||
19 | ]; |
||
20 | |||
21 | public function getCMSFields() |
||
84 | |||
85 | /** |
||
86 | * Get the colour for a column |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function ColumnColour($column) |
||
96 | |||
97 | public function IsLayout($layout){ |
||
100 | |||
101 | /** |
||
102 | * Gets the configured classes for a column |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | View Code Duplication | public function ColumnClasses() |
|
114 | |||
115 | /** |
||
116 | * Gets the configured classes for a row |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | View Code Duplication | public function RowClasses() |
|
128 | |||
129 | /** |
||
130 | * Gets the block type for CMS display |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getBlockType() |
||
138 | |||
139 | /** |
||
140 | * Renders the block for template |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function RenderBlock() |
||
149 | |||
150 | } |
||
151 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.