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 LoadB2bCustomerEmailData extends AbstractFixture implements DependentFixtureInterface |
|
|
|||
13 | { |
||
14 | const FIRST_ENTITY_NAME = '[email protected]'; |
||
15 | const SECOND_ENTITY_NAME = '[email protected]'; |
||
16 | const THIRD_ENTITY_NAME = '[email protected]'; |
||
17 | |||
18 | public function getDependencies() |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $b2bCustomerEmailData = [ |
||
29 | [ |
||
30 | 'email' => self::FIRST_ENTITY_NAME, |
||
31 | 'primary' => true, |
||
32 | ], |
||
33 | [ |
||
34 | 'email' => self::SECOND_ENTITY_NAME, |
||
35 | 'primary' => false, |
||
36 | ], |
||
37 | [ |
||
38 | 'email' => self::THIRD_ENTITY_NAME, |
||
39 | 'primary' => false, |
||
40 | ] |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function load(ObjectManager $manager) |
||
70 | } |
||
71 |
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.