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 | View Code Duplication | class Totals implements PluginInterface |
|
|
|||
15 | { |
||
16 | /** |
||
17 | * @var InfoProvider |
||
18 | */ |
||
19 | protected $infoProvider; |
||
20 | |||
21 | /** |
||
22 | * @var Configuration |
||
23 | */ |
||
24 | protected $configuration; |
||
25 | |||
26 | /** |
||
27 | * Info constructor. |
||
28 | * @param InfoProvider $infoProvider |
||
29 | */ |
||
30 | 8 | public function __construct(InfoProvider $infoProvider) |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 8 | public function setNode(Node $node) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 1 | public function getSlug(): string |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 1 | public function getCategorySlug(): string |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 1 | public function getCapabilities(): array |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 2 | public function getConfiguration(): PromiseInterface |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 2 | public function getValues(): PromiseInterface |
|
107 | } |
||
108 |
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.