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 |
||
31 | View Code Duplication | class EntityForm extends Application\UI\Form |
|
|
|||
32 | { |
||
33 | /** |
||
34 | * Implement entity handling in form |
||
35 | */ |
||
36 | use TEntityContainer; |
||
37 | |||
38 | /** |
||
39 | * Implement form methods |
||
40 | */ |
||
41 | use TForm; |
||
42 | |||
43 | /** |
||
44 | * @var ORM\EntityManager |
||
45 | */ |
||
46 | private $entityManager; |
||
47 | |||
48 | /** |
||
49 | * @param ORM\EntityManager $entityManager |
||
50 | */ |
||
51 | public function injectEntityManager(ORM\EntityManager $entityManager) : void |
||
55 | |||
56 | /** |
||
57 | * Adds naming container to the form |
||
58 | * |
||
59 | * @param string $name |
||
60 | * |
||
61 | * @return EntityContainer |
||
62 | */ |
||
63 | public function addContainer($name) : EntityContainer |
||
70 | |||
71 | /** |
||
72 | * @return ORM\EntityManager |
||
73 | */ |
||
74 | protected function getEntityManager() : ORM\EntityManager |
||
78 | } |
||
79 |
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.