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 |
||
24 | View Code Duplication | class AlterEvent extends Event |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Reference to the target instance. |
||
28 | * |
||
29 | * @var TemplateResolver |
||
30 | */ |
||
31 | private $instance; |
||
32 | |||
33 | /** |
||
34 | * @return TemplateResolver |
||
35 | */ |
||
36 | protected function get_instance() |
||
40 | |||
41 | /** |
||
42 | * @param TemplateResolver $template_resolver |
||
43 | */ |
||
44 | protected function set_instance(TemplateResolver $template_resolver) |
||
48 | |||
49 | /** |
||
50 | * Initializes the {@link $instance} property. |
||
51 | * |
||
52 | * @param TemplateResolver $target |
||
53 | */ |
||
54 | public function __construct(TemplateResolver &$target) |
||
60 | } |
||
61 |
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.