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 |
||
24 | class SlackTemplatingManager |
||
25 | { |
||
26 | /** @var array */ |
||
27 | private $config; |
||
28 | |||
29 | /** @var SlackTemplateInterface */ |
||
30 | private $template; |
||
31 | |||
32 | /** |
||
33 | * SlackTemplatingManager constructor. |
||
34 | * |
||
35 | * @param array $config |
||
36 | */ |
||
37 | public function __construct(array $config) |
||
41 | |||
42 | /** |
||
43 | * @param SlackTemplateInterface $template |
||
44 | * |
||
45 | * @return SlackTemplatingManager |
||
46 | */ |
||
47 | public function setTemplate(SlackTemplateInterface $template): SlackTemplatingManager |
||
53 | |||
54 | /** |
||
55 | * @return SlackMessage |
||
56 | */ |
||
57 | public function getMessage(): SlackMessage |
||
61 | |||
62 | /** |
||
63 | * @return SlackMessage |
||
64 | */ |
||
65 | private function getMessageWithDefaults(): SlackMessage |
||
89 | } |
||
90 |
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.