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 |
||
| 18 | class GithubController extends CommonController |
||
| 19 | { |
||
| 20 | protected $_name; |
||
| 21 | protected $_vendor; |
||
| 22 | protected $_description; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string GitHub OAuth access token |
||
| 26 | */ |
||
| 27 | protected $_token; |
||
| 28 | |||
| 29 | public function setFull_name($value) |
||
| 33 | |||
| 34 | public function getFull_name() |
||
| 38 | |||
| 39 | public function setFullName($value) |
||
| 43 | |||
| 44 | public function getFullName() |
||
| 48 | |||
| 49 | public function setName($value) |
||
| 53 | |||
| 54 | public function getName() |
||
| 62 | |||
| 63 | public function setVendor($value) |
||
| 67 | |||
| 68 | public function getVendor() |
||
| 76 | |||
| 77 | public function setDescription($value) |
||
| 81 | |||
| 82 | View Code Duplication | public function getDescription() |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Create the repo on GitHub. |
||
| 93 | * @return int exit code |
||
| 94 | */ |
||
| 95 | public function actionCreate() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Clone repo from github. |
||
| 111 | * TODO this action must be run without `start`. |
||
| 112 | * @param string $repo full name vendor/package |
||
| 113 | * @return int exit code |
||
| 114 | */ |
||
| 115 | public function actionClone($repo) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Checks if repo exists. |
||
| 122 | * @param string $repo full name vendor/package defaults to this repo name |
||
| 123 | * @return int exit code |
||
| 124 | */ |
||
| 125 | public function actionExists($repo = null) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Check if repo exists. |
||
| 132 | * @param string $repo |
||
| 133 | * @return bool |
||
| 134 | */ |
||
| 135 | public static function exists($repo) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Creates github release. |
||
| 142 | */ |
||
| 143 | public function actionRelease($release = null) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Waits until push is actually finished. |
||
| 161 | * TODO Check github if it really has latest local commit. |
||
| 162 | * @return int 0 - success, 1 - failed |
||
| 163 | */ |
||
| 164 | public function actionWaitPush() |
||
| 170 | |||
| 171 | public function request($method, $path, $data) |
||
| 177 | |||
| 178 | public function findToken() |
||
| 182 | |||
| 183 | public function getToken() |
||
| 191 | } |
||
| 192 |
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.