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 | View Code Duplication | class Zip implements |
|
|
|||
24 | CompressionTypeInterface, |
||
25 | CompressorInterface, |
||
26 | DeCompressorInterface, |
||
27 | LoggerAwareInterface, |
||
28 | BuilderAwareInterface |
||
29 | { |
||
30 | use GetOptionTrait; |
||
31 | use FileProcessTrait; |
||
32 | use OptionalLoggerTrait; |
||
33 | use CompressorTrait; |
||
34 | use DeCompressorTrait; |
||
35 | |||
36 | const NAME = 'zip'; |
||
37 | |||
38 | /** |
||
39 | * Get the extension used by this compressor |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | 6 | public function getExtension() |
|
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | 18 | public function getName() |
|
55 | |||
56 | /** |
||
57 | * Get the command line to compress a file |
||
58 | * |
||
59 | * @param LocalFileNodeInterface $from |
||
60 | * @param LocalFileNodeInterface $to |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 6 | public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
68 | |||
69 | /** |
||
70 | * Get the command line to decompress a file |
||
71 | * |
||
72 | * @param LocalFileNodeInterface $from |
||
73 | * @param LocalFileNodeInterface $to |
||
74 | * |
||
75 | * @return string |
||
76 | * |
||
77 | */ |
||
78 | 4 | public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to) |
|
82 | } |
||
83 |
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.