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 |
||
17 | class ZipVersionProbe implements VersionProbeInterface |
||
18 | { |
||
19 | private $isSupported; |
||
20 | private $inflator; |
||
21 | private $deflator; |
||
22 | |||
23 | public function __construct(ProcessBuilderFactoryInterface $inflator, ProcessBuilderFactoryInterface $deflator) |
||
28 | |||
29 | /** |
||
30 | * Set the inflator to zip |
||
31 | * |
||
32 | * @param ProcessBuilderFactoryInterface $inflator |
||
33 | * @return ZipVersionProbe |
||
34 | */ |
||
35 | public function setInflator(ProcessBuilderFactoryInterface $inflator) |
||
41 | |||
42 | /** |
||
43 | * Set the deflator to unzip |
||
44 | * |
||
45 | * @param ProcessBuilderFactoryInterface $deflator |
||
46 | * @return ZipVersionProbe |
||
47 | */ |
||
48 | public function setDeflator(ProcessBuilderFactoryInterface $deflator) |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function getStatus() |
||
96 | } |
||
97 |
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.