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 |
||
| 34 | abstract class AbstractCommand extends Command |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * Input object |
||
| 38 | * |
||
| 39 | * @var \Symfony\Component\Console\Input\InputInterface |
||
| 40 | */ |
||
| 41 | protected $input; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Output object |
||
| 45 | * |
||
| 46 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
| 47 | */ |
||
| 48 | protected $output; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Cached user config |
||
| 52 | * |
||
| 53 | * @var Config |
||
| 54 | */ |
||
| 55 | protected $config; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Configure command |
||
| 59 | * |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | protected function configure() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Initialize command |
||
| 88 | * |
||
| 89 | * @param InputInterface $input |
||
| 90 | * @param OutputInterface $output |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get the account id specified, or from the config |
||
| 102 | * |
||
| 103 | * @return string|boolean |
||
| 104 | */ |
||
| 105 | View Code Duplication | public function getAccountId() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Get the access token specified, or from the config |
||
| 117 | * |
||
| 118 | * @return string|boolean |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function getAccessToken() |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Get the user's config |
||
| 132 | * |
||
| 133 | * @return Config |
||
| 134 | */ |
||
| 135 | public function getConfig() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Output information in the correct format |
||
| 145 | * |
||
| 146 | * @param array|string $messages |
||
| 147 | * |
||
| 148 | * @return void |
||
| 149 | */ |
||
| 150 | protected function out($messages = array()) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Output in default format |
||
| 164 | * |
||
| 165 | * @param array|string $messages |
||
| 166 | * |
||
| 167 | * @return void |
||
| 168 | */ |
||
| 169 | protected function outputFormatDefault($messages) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Output in json format |
||
| 191 | * |
||
| 192 | * @param array|string $messages |
||
| 193 | * |
||
| 194 | * @return void |
||
| 195 | */ |
||
| 196 | protected function outputFormatJson($messages) |
||
| 222 | } |
||
| 223 |