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 |
||
| 3 | class MapLayerExtension extends DataExtension |
||
| 4 | { |
||
| 5 | public static $many_many = array( |
||
| 6 | 'MapLayers' => 'MapLayer', |
||
| 7 | ); |
||
| 8 | |||
| 9 | public static $belongs_many_many_extraFields = array( |
||
| 10 | 'MapLayers' => array( |
||
| 11 | 'SortOrder' => 'Int', |
||
| 12 | ), |
||
| 13 | ); |
||
| 14 | |||
| 15 | 1 | View Code Duplication | public function updateCMSFields(FieldList $fields) |
| 33 | |||
| 34 | /** |
||
| 35 | 10 | * Only set has geo to true if layers exist |
|
| 36 | * @param boolean &$hasGeo will be set to true if any layers |
||
| 37 | 10 | */ |
|
| 38 | 1 | public function updateHasGeo(&$hasGeo) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Add layers if the exist to a map from the MapExtension |
||
| 47 | 2 | * @param MapAPI &$map object representing the map |
|
| 48 | * @param boolean &$autozoom true to auto zoom, false not to |
||
| 49 | */ |
||
| 50 | 2 | public function updateBasicMap(&$map, &$autozoom) |
|
| 59 | } |
||
| 60 |
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.