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 |
||
| 15 | class Composer |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var Balloon[] |
||
| 19 | */ |
||
| 20 | private $composerConfigManager = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Executor |
||
| 24 | */ |
||
| 25 | private $executor; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var BalloonFactory |
||
| 29 | */ |
||
| 30 | private $balloonFactory; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param Executor $executor |
||
| 34 | * @param BalloonFactory $balloonFactory |
||
| 35 | */ |
||
| 36 | 28 | public function __construct(Executor $executor, BalloonFactory $balloonFactory) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @param Project $project |
||
| 44 | * @param array $options |
||
| 45 | * @return int |
||
| 46 | */ |
||
| 47 | 9 | public function createProject(Project $project, array $options = array()) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $name |
||
| 68 | * @param string $version |
||
| 69 | * @param bool $isGlobal |
||
| 70 | * @param array $options |
||
| 71 | * @return int |
||
| 72 | */ |
||
| 73 | 4 | View Code Duplication | public function requirePackage($name, $version = '', $isGlobal = false, array $options = array()) |
| 81 | |||
| 82 | /** |
||
| 83 | * @param $name |
||
| 84 | * @param bool $isGlobal |
||
| 85 | * @param array $options |
||
| 86 | * @return int |
||
| 87 | */ |
||
| 88 | 3 | View Code Duplication | public function updatePackage($name, $isGlobal = false, array $options = array()) |
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $name |
||
| 99 | * @param bool $isGlobal |
||
| 100 | * @param array $options |
||
| 101 | * @return int |
||
| 102 | */ |
||
| 103 | 3 | View Code Duplication | public function removePackage($name, $isGlobal = false, array $options = array()) |
| 111 | |||
| 112 | /** |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | 4 | public function getHomePath() |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @param $cwd |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | 4 | public function getConfigPath($cwd = '') |
|
| 131 | |||
| 132 | /** |
||
| 133 | * @param string $cwd |
||
| 134 | * @return array |
||
| 135 | */ |
||
| 136 | 2 | public function getConfig($cwd = '') |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @param array $config |
||
| 143 | * @param string $cwd |
||
| 144 | * @return int |
||
| 145 | */ |
||
| 146 | public function setConfig(array $config, $cwd = '') |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $cwd |
||
| 153 | * @return int |
||
| 154 | */ |
||
| 155 | public function flushConfig($cwd = '') |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param string $cwd |
||
| 162 | * @return int |
||
| 163 | */ |
||
| 164 | 2 | public function validateConfig($cwd = '') |
|
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $cwd |
||
| 171 | * @return int |
||
| 172 | */ |
||
| 173 | 1 | public function dumpAutoload($cwd = '') |
|
| 177 | |||
| 178 | /** |
||
| 179 | * @param array $options |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | 18 | private function mapOptions(array $options) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Getter of $composerConfigManager |
||
| 193 | * |
||
| 194 | * @param $cwd |
||
| 195 | * @return Balloon |
||
| 196 | */ |
||
| 197 | 2 | public function getComposerConfigManager($cwd) |
|
| 204 | |||
| 205 | /** |
||
| 206 | * Getter of $executor |
||
| 207 | * |
||
| 208 | * @return Executor |
||
| 209 | */ |
||
| 210 | 22 | private function getExecutor() |
|
| 214 | |||
| 215 | /** |
||
| 216 | * Setter of $executor |
||
| 217 | * |
||
| 218 | * @param Executor $executor |
||
| 219 | */ |
||
| 220 | 28 | private function setExecutor(Executor $executor) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * Getter of $balloonFactory |
||
| 227 | * |
||
| 228 | * @return BalloonFactory |
||
| 229 | */ |
||
| 230 | 2 | private function getBalloonFactory() |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Setter of $balloonFactory |
||
| 237 | * |
||
| 238 | * @param BalloonFactory $balloonFactory |
||
| 239 | */ |
||
| 240 | 28 | private function setBalloonFactory(BalloonFactory $balloonFactory) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @param string $command |
||
| 247 | * @param string $cwd |
||
| 248 | * @return int |
||
| 249 | */ |
||
| 250 | 21 | private function execute($command, $cwd = null) |
|
| 255 | } |
||
| 256 |