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 |
||
16 | class PushCommand extends Command |
||
17 | { |
||
18 | /** |
||
19 | * @var GuzzleHttp\ClientInterface |
||
20 | */ |
||
21 | private $client; |
||
22 | |||
23 | /** |
||
24 | * Configures the push command. |
||
25 | */ |
||
26 | 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) |
|
65 | |||
66 | /** |
||
67 | * Returns the value for log option. |
||
68 | * |
||
69 | * If the log option is not provided, STDIN is being used instead. |
||
70 | * |
||
71 | * @param InputInterface $input |
||
72 | * @throws \RuntimeException |
||
73 | * @return mixed|string |
||
74 | */ |
||
75 | 3 | View Code Duplication | public function getOptionLog(InputInterface $input) |
87 | |||
88 | /** |
||
89 | * @param GuzzleHttp\ClientInterface $client |
||
90 | */ |
||
91 | 3 | public function setClient(ClientInterface $client) |
|
95 | |||
96 | /** |
||
97 | * @return Client |
||
98 | */ |
||
99 | 3 | public function getClient() |
|
103 | } |
||
104 |
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.