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 |
||
| 36 | class Repositories extends AbstractPackage |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * List your repositories. |
||
| 40 | * |
||
| 41 | * List repositories for the authenticated user. |
||
| 42 | * |
||
| 43 | * @param string $type Sort type. all, owner, public, private, member. Default: all. |
||
| 44 | * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. |
||
| 45 | * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. |
||
| 46 | * |
||
| 47 | * @return object |
||
| 48 | * |
||
| 49 | * @since 1.0 |
||
| 50 | * @throws \RuntimeException |
||
| 51 | */ |
||
| 52 | public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') |
||
| 83 | |||
| 84 | /** |
||
| 85 | * List user repositories. |
||
| 86 | * |
||
| 87 | * List public repositories for the specified user. |
||
| 88 | * |
||
| 89 | * @param string $user The user name. |
||
| 90 | * @param string $type Sort type. all, owner, member. Default: all. |
||
| 91 | * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. |
||
| 92 | * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. |
||
| 93 | * |
||
| 94 | * @return object |
||
| 95 | * |
||
| 96 | * @since 1.0 |
||
| 97 | * @throws \RuntimeException |
||
| 98 | */ |
||
| 99 | public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '') |
||
| 130 | |||
| 131 | /** |
||
| 132 | * List organization repositories. |
||
| 133 | * |
||
| 134 | * List repositories for the specified org. |
||
| 135 | * |
||
| 136 | * @param string $org The name of the organization. |
||
| 137 | * @param string $type Sort type. all, public, private, forks, sources, member. Default: all. |
||
| 138 | * |
||
| 139 | * @return object |
||
| 140 | * |
||
| 141 | * @since 1.0 |
||
| 142 | * @throws \RuntimeException |
||
| 143 | */ |
||
| 144 | public function getListOrg($org, $type = 'all') |
||
| 160 | |||
| 161 | /** |
||
| 162 | * List all public repositories. |
||
| 163 | * |
||
| 164 | * This provides a dump of every repository, in the order that they were created. |
||
| 165 | * |
||
| 166 | * @param integer $id The integer ID of the last Repository that you’ve seen. |
||
| 167 | * |
||
| 168 | * @return object |
||
| 169 | * |
||
| 170 | * @since 1.0 |
||
| 171 | * @throws \RuntimeException |
||
| 172 | */ |
||
| 173 | View Code Duplication | public function getList($id = 0) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * Create. |
||
| 187 | * |
||
| 188 | * Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope. |
||
| 189 | * |
||
| 190 | * @param string $name The repository name. |
||
| 191 | * @param string $org The organization name (if needed). |
||
| 192 | * @param string $description The repository description. |
||
| 193 | * @param string $homepage The repository homepage. |
||
| 194 | * @param boolean $private Set true to create a private repository, false to create a public one. |
||
| 195 | * Creating private repositories requires a paid GitHub account. |
||
| 196 | * @param boolean $has_issues Set true to enable issues for this repository, false to disable them. |
||
| 197 | * @param boolean $has_wiki Set true to enable the wiki for this repository, false to disable it. |
||
| 198 | * @param boolean $has_downloads Set true to enable downloads for this repository, false to disable them. |
||
| 199 | * @param integer $team_id The id of the team that will be granted access to this repository. |
||
| 200 | * This is only valid when creating a repo in an organization. |
||
| 201 | * @param boolean $auto_init true to create an initial commit with empty README. |
||
| 202 | * @param string $gitignore_template Desired language or platform .gitignore template to apply. |
||
| 203 | * Use the name of the template without the extension. |
||
| 204 | * For example, “Haskell” Ignored if auto_init parameter is not provided. |
||
| 205 | * |
||
| 206 | * @return object |
||
| 207 | * |
||
| 208 | * @since 1.0 |
||
| 209 | */ |
||
| 210 | public function create($name, $org = '', $description = '', $homepage = '', $private = false, $has_issues = false, |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Get. |
||
| 241 | * |
||
| 242 | * @param string $owner Repository owner. |
||
| 243 | * @param string $repo Repository name. |
||
| 244 | * |
||
| 245 | * @return object |
||
| 246 | * |
||
| 247 | * @since 1.0 |
||
| 248 | */ |
||
| 249 | public function get($owner, $repo) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Edit. |
||
| 262 | * |
||
| 263 | * @param string $owner Repository owner. |
||
| 264 | * @param string $repo Repository name. |
||
| 265 | * @param string $name The repository name. |
||
| 266 | * @param string $description The repository description. |
||
| 267 | * @param string $homepage The repository homepage. |
||
| 268 | * @param boolean $private Set true to create a private repository, false to create a public one. |
||
| 269 | * Creating private repositories requires a paid GitHub account. |
||
| 270 | * @param boolean $has_issues Set true to enable issues for this repository, false to disable them. |
||
| 271 | * @param boolean $has_wiki Set true to enable the wiki for this repository, false to disable it. |
||
| 272 | * @param boolean $has_downloads Set true to enable downloads for this repository, false to disable them. |
||
| 273 | * @param string $default_branch Update the default branch for this repository |
||
| 274 | * |
||
| 275 | * @return object |
||
| 276 | * |
||
| 277 | * @since 1.0 |
||
| 278 | */ |
||
| 279 | public function edit($owner, $repo, $name, $description = '', $homepage = '', $private = false, $has_issues = false, |
||
| 300 | |||
| 301 | /** |
||
| 302 | * List contributors. |
||
| 303 | * |
||
| 304 | * @param string $owner Repository owner. |
||
| 305 | * @param string $repo Repository name. |
||
| 306 | * @param boolean $anon Set to 1 or true to include anonymous contributors in results. |
||
| 307 | * |
||
| 308 | * @return object |
||
| 309 | * |
||
| 310 | * @since 1.0 |
||
| 311 | */ |
||
| 312 | View Code Duplication | public function getListContributors($owner, $repo, $anon = false) |
|
| 324 | |||
| 325 | /** |
||
| 326 | * List languages. |
||
| 327 | * |
||
| 328 | * List languages for the specified repository. The value on the right of a language is the number of bytes of code |
||
| 329 | * written in that language. |
||
| 330 | * |
||
| 331 | * @param string $owner Repository owner. |
||
| 332 | * @param string $repo Repository name. |
||
| 333 | * |
||
| 334 | * @return object |
||
| 335 | * |
||
| 336 | * @since 1.0 |
||
| 337 | */ |
||
| 338 | public function getListLanguages($owner, $repo) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * List Teams |
||
| 351 | * |
||
| 352 | * @param string $owner Repository owner. |
||
| 353 | * @param string $repo Repository name. |
||
| 354 | * |
||
| 355 | * @return object |
||
| 356 | * |
||
| 357 | * @since 1.0 |
||
| 358 | */ |
||
| 359 | public function getListTeams($owner, $repo) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * List Tags. |
||
| 372 | * |
||
| 373 | * @param string $owner Repository owner. |
||
| 374 | * @param string $repo Repository name. |
||
| 375 | * |
||
| 376 | * @return object |
||
| 377 | * |
||
| 378 | * @since 1.0 |
||
| 379 | */ |
||
| 380 | public function getListTags($owner, $repo) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * List Branches. |
||
| 393 | * |
||
| 394 | * @param string $owner Repository owner. |
||
| 395 | * @param string $repo Repository name. |
||
| 396 | * |
||
| 397 | * @return object |
||
| 398 | * |
||
| 399 | * @since 1.0 |
||
| 400 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::getList() instead |
||
| 401 | */ |
||
| 402 | public function getListBranches($owner, $repo) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Get a Branch. |
||
| 409 | * |
||
| 410 | * @param string $owner Repository owner. |
||
| 411 | * @param string $repo Repository name. |
||
| 412 | * @param string $branch Branch name. |
||
| 413 | * |
||
| 414 | * @return object |
||
| 415 | * |
||
| 416 | * @since 1.0 |
||
| 417 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::get() instead |
||
| 418 | */ |
||
| 419 | public function getBranch($owner, $repo, $branch) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Delete a Repository. |
||
| 426 | * |
||
| 427 | * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required. |
||
| 428 | * |
||
| 429 | * @param string $owner Repository owner. |
||
| 430 | * @param string $repo Repository name. |
||
| 431 | * |
||
| 432 | * @return object |
||
| 433 | * |
||
| 434 | * @since 1.0 |
||
| 435 | */ |
||
| 436 | public function delete($owner, $repo) |
||
| 446 | } |
||
| 447 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.