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 |
||
22 | class LoadUserData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface |
||
23 | { |
||
24 | /** |
||
25 | * System container. |
||
26 | * |
||
27 | * @var ContainerInterface |
||
28 | */ |
||
29 | private $container; |
||
30 | |||
31 | /** |
||
32 | * Set container. |
||
33 | * |
||
34 | * @param ContainerInterface $container |
||
35 | * {@inheritDoc} |
||
36 | */ |
||
37 | 49 | public function setContainer(ContainerInterface $container = null) |
|
41 | |||
42 | /** |
||
43 | * Load fixtures into db. |
||
44 | * |
||
45 | * {@inheritDoc} |
||
46 | * |
||
47 | * @param ObjectManager $manager |
||
48 | */ |
||
49 | 49 | public function load(ObjectManager $manager) |
|
57 | |||
58 | /** |
||
59 | * Add admin user. |
||
60 | * |
||
61 | * @param ObjectManager $manager [description] |
||
62 | */ |
||
63 | 49 | View Code Duplication | private function addAdmin($manager) |
80 | |||
81 | /** |
||
82 | * Add editor user. |
||
83 | * |
||
84 | * @param ObjectManager $manager [description] |
||
85 | */ |
||
86 | 49 | View Code Duplication | private function addEditor($manager) |
103 | |||
104 | /** |
||
105 | * Add Test user. |
||
106 | * |
||
107 | * @param ObjectManager $manager [description] |
||
108 | */ |
||
109 | 49 | View Code Duplication | private function addTestUser($manager) |
126 | |||
127 | |||
128 | /** |
||
129 | * Get fixture order. |
||
130 | * |
||
131 | * @return [type] [description] |
||
132 | */ |
||
133 | 49 | public function getOrder() |
|
137 | } |
||
138 |
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.