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 |
||
21 | View Code Duplication | class DecoderProvider extends ContainerAwareTrait implements DecoderProviderInterface |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $decoders; |
||
27 | |||
28 | /** |
||
29 | * The constructor class. |
||
30 | * |
||
31 | * @param array $decoders List of decoders (default empty). |
||
32 | */ |
||
33 | public function __construct(array $decoders = []) |
||
37 | |||
38 | /** |
||
39 | * @param string $format The format of decoder. |
||
40 | * |
||
41 | * @throws \InvalidArgumentException |
||
42 | * |
||
43 | * @return DecoderInterface |
||
44 | */ |
||
45 | public function getDecoder($format) |
||
53 | |||
54 | /** |
||
55 | * Tests whether a decoder for a given format exists. |
||
56 | * |
||
57 | * @param string $format The format. |
||
58 | * |
||
59 | * @return boolean |
||
60 | */ |
||
61 | protected function supports($format) |
||
65 | } |
||
66 |
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.