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 |
||
15 | final class BuildCommandBusStackPass implements CompilerPassInterface |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | 6 | public function process(ContainerBuilder $container) |
|
48 | |||
49 | 5 | private function searchServices(ContainerBuilder $container): array |
|
50 | { |
||
51 | 5 | $services = $container->findTaggedServiceIds('innmind_command_bus'); |
|
52 | 5 | $map = []; |
|
53 | |||
54 | 5 | View Code Duplication | foreach ($services as $id => $tags) { |
1 ignored issue
–
show
|
|||
55 | 5 | foreach ($tags as $tag => $attributes) { |
|
56 | 5 | if (!isset($attributes['alias'])) { |
|
57 | 1 | throw new LogicException; |
|
58 | } |
||
59 | |||
60 | 4 | $map[$attributes['alias']] = $id; |
|
61 | } |
||
62 | } |
||
63 | |||
64 | 4 | return $map; |
|
65 | } |
||
66 | |||
67 | 3 | private function inject( |
|
92 | } |
||
93 |
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.