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 MonitorCommand extends Command |
||
18 | { |
||
19 | /** |
||
20 | * @var GuzzleHttp\ClientInterface |
||
21 | */ |
||
22 | private $client; |
||
23 | |||
24 | /** |
||
25 | * Configures the monitor command. |
||
26 | */ |
||
27 | 3 | protected function configure() |
|
38 | |||
39 | /** |
||
40 | * Executes the monitor command. |
||
41 | * |
||
42 | * @param InputInterface $input An InputInterface instance |
||
43 | * @param OutputInterface $output An OutputInterface instance |
||
44 | * |
||
45 | * @return null|int null or 0 if everything went fine, or an error code |
||
46 | */ |
||
47 | 3 | protected function execute(InputInterface $input, OutputInterface $output) |
|
71 | |||
72 | /** |
||
73 | * Returns the command to monitor. |
||
74 | * |
||
75 | * If monitor argument is not provided, STDIN is being used instead. |
||
76 | * |
||
77 | * @param InputInterface $input |
||
78 | * @throws \RuntimeException |
||
79 | * @return string |
||
80 | */ |
||
81 | 3 | View Code Duplication | private function getMonitorArgument(InputInterface $input) |
97 | |||
98 | /** |
||
99 | * @param GuzzleHttp\ClientInterface $client |
||
100 | */ |
||
101 | 3 | public function setClient(ClientInterface $client) |
|
105 | |||
106 | /** |
||
107 | * @return Client |
||
108 | */ |
||
109 | 3 | public function getClient() |
|
113 | } |
||
114 |
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.