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 Get extends Command |
||
18 | { |
||
19 | /** |
||
20 | * Configures the command's options. |
||
21 | * |
||
22 | * @return void |
||
23 | */ |
||
24 | protected function configure() |
||
34 | |||
35 | /** |
||
36 | * Gets the password(s) for the specified application(s). |
||
37 | * |
||
38 | * @param \Symfony\Component\Console\Input\InputInterface $input The command input. |
||
39 | * @param \Symfony\Component\Console\Output\OutputInterface $output The command output. |
||
40 | * @return int The return status |
||
41 | */ |
||
42 | protected function execute(InputInterface $input, OutputInterface $output) |
||
58 | |||
59 | /** |
||
60 | * Format the passwords according to the output format. |
||
61 | * |
||
62 | * @param array<array> $passwords The passwords to format. |
||
63 | * @param string $outputFormat The output format (valid: json). |
||
64 | * @return string The formatted passwords for display. |
||
65 | */ |
||
66 | private function _formatPasswords(array $passwords, $outputFormat) |
||
75 | |||
76 | /** |
||
77 | * Prints an error message and returns the given error code. |
||
78 | * |
||
79 | * @param \Symfony\Component\Console\Output\OutputInterface $output The command output. |
||
80 | * @param string $message The message to output. |
||
81 | * @param int $code The return status. |
||
82 | * @return int The return status |
||
83 | */ |
||
84 | View Code Duplication | private function _error(OutputInterface $output, $message, $code = 1) |
|
91 | } |
||
92 |
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.