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) { |
| 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 |