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 |
||
14 | class SafeBrowsingExtension extends Extension |
||
15 | { |
||
16 | /** |
||
17 | * Main service ID. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | const SERVICE_ID = 'safe_browsing_bundle.validator.constraints.safe_validator'; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 15 | public function load(array $configs, ContainerBuilder $container) |
|
40 | |||
41 | /** |
||
42 | * Set cache directory. |
||
43 | * |
||
44 | * @param string $cache |
||
45 | * @param ContainerBuilder $container |
||
46 | */ |
||
47 | 15 | View Code Duplication | private function setCache($cache, ContainerBuilder $container) |
57 | |||
58 | /** |
||
59 | * Initialize service configuration. |
||
60 | * |
||
61 | * @param array $configs |
||
62 | * @param ContainerBuilder $container |
||
63 | */ |
||
64 | 15 | private function setConfigs(array $configs, ContainerBuilder $container) |
|
70 | |||
71 | /** |
||
72 | * Set HTTP client. |
||
73 | * |
||
74 | * @param string $httpClient |
||
75 | * @param ContainerBuilder $container |
||
76 | */ |
||
77 | 15 | View Code Duplication | private function setHttpClient($httpClient, ContainerBuilder $container) |
87 | } |
||
88 |
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.