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 | final class DefinitionParser |
||
23 | { |
||
24 | /** |
||
25 | * @var ServiceParser |
||
26 | */ |
||
27 | private $serviceParser; |
||
28 | |||
29 | 44 | public function __construct(ResolverInterface $serviceResolver) |
|
33 | |||
34 | /** |
||
35 | * Parses a service definition and register it to the container. |
||
36 | * |
||
37 | * @param ContainerBuilder $container |
||
38 | * @param string $id |
||
39 | * @param array|string $service |
||
40 | * @param string $fileName file name |
||
41 | * |
||
42 | * @throws InvalidArgumentException |
||
43 | */ |
||
44 | 32 | public function parse(ContainerBuilder $container, $id, $service, $fileName) |
|
66 | } |
||
67 |
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.