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 |
||
41 | class AppKernel extends Kernel |
||
42 | { |
||
43 | public function registerBundles() : array |
||
44 | { |
||
45 | $bundles = [ |
||
46 | new AppBundle(), |
||
47 | new DoctrineBundle(), |
||
48 | new DoctrineMigrationsBundle(), |
||
49 | new DoctrineOrmBridgeBundle(), |
||
50 | new FrameworkBundle(), |
||
51 | new HttplugBundle(), |
||
52 | new MonologBundle(), |
||
53 | new NelmioCorsBundle(), |
||
54 | new OldSoundRabbitMqBundle(), |
||
55 | new OverblogGraphQLBundle(), |
||
56 | new SecurityBundle(), |
||
57 | new SimpleBusCommandBusBundle(), |
||
58 | new SimpleBusEventBusBundle(), |
||
59 | new SwiftmailerBundle(), |
||
60 | new TwigBundle(), |
||
61 | new WarezgibzzzQueryBusBundle(), |
||
62 | ]; |
||
63 | |||
64 | View Code Duplication | if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { |
|
|
|||
65 | $bundles[] = new DebugBundle(); |
||
66 | $bundles[] = new DoctrineFixturesBundle(); |
||
67 | $bundles[] = new SensioDistributionBundle(); |
||
68 | $bundles[] = new WebProfilerBundle(); |
||
69 | } |
||
70 | |||
71 | return $bundles; |
||
72 | } |
||
73 | |||
74 | public function getRootDir() : string |
||
78 | |||
79 | public function getCacheDir() : string |
||
83 | |||
84 | public function getLogDir() : string |
||
88 | |||
89 | public function registerContainerConfiguration(LoaderInterface $loader) : void |
||
93 | |||
94 | protected function getContainerBaseClass() : string |
||
102 | } |
||
103 |
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.