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 |
||
23 | class ParametersParser implements ParserInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var ResolverInterface |
||
27 | */ |
||
28 | private $serviceResolver; |
||
29 | |||
30 | 14 | public function __construct(ResolverInterface $serviceResolver = null) |
|
34 | |||
35 | /** |
||
36 | * Parses parameters and register them to the container. |
||
37 | * |
||
38 | * @param ContainerBuilder $container |
||
39 | * @param array $content YAML file content |
||
40 | * @param string $fileName file name |
||
41 | * |
||
42 | * @throws InvalidArgumentException |
||
43 | */ |
||
44 | 14 | public function parse(ContainerBuilder $container, $content, $fileName) |
|
60 | } |
||
61 |
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.