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 |
||
| 27 | class RsyncTask extends \Netresearch\Kite\Task\ScpTask |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $defaultOptions = array( |
||
| 33 | 'compress' => true, |
||
| 34 | 'rsh' => 'ssh{node.sshOptions}', |
||
| 35 | 'recursive' => true, |
||
| 36 | 'times' => true, |
||
| 37 | // 'perms', |
||
| 38 | 'links' => true |
||
| 39 | /* 'delete', |
||
| 40 | 'delete-excluded' */ |
||
| 41 | ); |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | protected $defaultRules = array( |
||
| 47 | 'exclude' => array( |
||
| 48 | '.*' |
||
| 49 | ), |
||
| 50 | 'include' => array( |
||
| 51 | '.htaccess' |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var |
||
| 57 | */ |
||
| 58 | protected $options; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Configure the options |
||
| 62 | * |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | View Code Duplication | protected function configureVariables() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Run the task |
||
| 89 | * |
||
| 90 | * @return array|mixed |
||
| 91 | */ |
||
| 92 | public function run() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get the rsync command |
||
| 112 | * |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | protected function getScpCommand() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Merge an (optional) array option into defaults |
||
| 131 | * |
||
| 132 | * Given f.e. that the option has the following value: |
||
| 133 | * array( |
||
| 134 | * 'debug', |
||
| 135 | * 'include' => '*', |
||
| 136 | * 'quiet' => null, |
||
| 137 | * ) |
||
| 138 | * |
||
| 139 | * and the defaults are: |
||
| 140 | * array( |
||
| 141 | * 'compress', |
||
| 142 | * 'quiet' |
||
| 143 | * ) |
||
| 144 | * |
||
| 145 | * the result would be: |
||
| 146 | * array( |
||
| 147 | * 'compress', |
||
| 148 | * 'debug', |
||
| 149 | * 'include' => '*' |
||
| 150 | * ) |
||
| 151 | * |
||
| 152 | * @param string $name The name |
||
| 153 | * @param array $defaults The defaults |
||
| 154 | * |
||
| 155 | * @return array |
||
| 156 | */ |
||
| 157 | protected function getMergedArrayOption($name, array $defaults) |
||
| 182 | } |
||
| 183 | ?> |
||
| 184 |
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.