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 |
||
12 | View Code Duplication | class Siimple2Template extends BaseTemplate implements TemplateInterface |
|
|
|||
13 | { |
||
14 | protected $prefix = ''; |
||
15 | protected $postfix = '<br />'; |
||
16 | protected $wrapper = '<div class="siimple-alert siimple-alert--%s">%s</div>'; |
||
17 | |||
18 | /** |
||
19 | * Override base function to suite Bootstrap 3 alert naming. |
||
20 | * |
||
21 | * @param $messages - message text |
||
22 | * @param $type - message type: success, info, warning, error |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | 3 | public function wrapMessages($messages, $type) |
|
32 | } |
||
33 |
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.