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 namespace Cornford\Googlmapper\Models; |
||
6 | View Code Duplication | class Circle implements ModelingInterface { |
|
|
|||
7 | |||
8 | /** |
||
9 | * Options. |
||
10 | * |
||
11 | * @var array |
||
12 | */ |
||
13 | protected $options = []; |
||
14 | |||
15 | /** |
||
16 | * Public constructor. |
||
17 | * |
||
18 | * @param array $parameters |
||
19 | */ |
||
20 | public function __construct(array $parameters = []) |
||
24 | |||
25 | /** |
||
26 | * Render the model item. |
||
27 | * |
||
28 | * @param integer $identifier |
||
29 | * @param View $view |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | public function render($identifier, View $view) |
||
40 | |||
41 | /** |
||
42 | * Get the model options. |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function getOptions() |
||
50 | |||
51 | } |
||
52 |
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.