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 $hasIssues Set true to enable issues for this repository, false to disable them. |
||
197 | * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. |
||
198 | * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. |
||
199 | * @param integer $teamId 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 $autoInit true to create an initial commit with empty README. |
||
202 | * @param string $gitignoreTemplate 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, $hasIssues = false, |
||
239 | |||
240 | /** |
||
241 | * Get. |
||
242 | * |
||
243 | * @param string $owner Repository owner. |
||
244 | * @param string $repo Repository name. |
||
245 | * |
||
246 | * @return object |
||
247 | * |
||
248 | * @since 1.0 |
||
249 | */ |
||
250 | public function get($owner, $repo) |
||
260 | |||
261 | /** |
||
262 | * Edit. |
||
263 | * |
||
264 | * @param string $owner Repository owner. |
||
265 | * @param string $repo Repository name. |
||
266 | * @param string $name The repository name. |
||
267 | * @param string $description The repository description. |
||
268 | * @param string $homepage The repository homepage. |
||
269 | * @param boolean $private Set true to create a private repository, false to create a public one. |
||
270 | * Creating private repositories requires a paid GitHub account. |
||
271 | * @param boolean $hasIssues Set true to enable issues for this repository, false to disable them. |
||
272 | * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. |
||
273 | * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. |
||
274 | * @param string $defaultBranch Update the default branch for this repository |
||
275 | * |
||
276 | * @return object |
||
277 | * |
||
278 | * @since 1.0 |
||
279 | */ |
||
280 | public function edit($owner, $repo, $name, $description = '', $homepage = '', $private = false, $hasIssues = false, |
||
302 | |||
303 | /** |
||
304 | * List contributors. |
||
305 | * |
||
306 | * @param string $owner Repository owner. |
||
307 | * @param string $repo Repository name. |
||
308 | * @param boolean $anon Set to 1 or true to include anonymous contributors in results. |
||
309 | * |
||
310 | * @return object |
||
311 | * |
||
312 | * @since 1.0 |
||
313 | */ |
||
314 | View Code Duplication | public function getListContributors($owner, $repo, $anon = false) |
|
326 | |||
327 | /** |
||
328 | * List languages. |
||
329 | * |
||
330 | * List languages for the specified repository. The value on the right of a language is the number of bytes of code |
||
331 | * written in that language. |
||
332 | * |
||
333 | * @param string $owner Repository owner. |
||
334 | * @param string $repo Repository name. |
||
335 | * |
||
336 | * @return object |
||
337 | * |
||
338 | * @since 1.0 |
||
339 | */ |
||
340 | public function getListLanguages($owner, $repo) |
||
350 | |||
351 | /** |
||
352 | * List Teams |
||
353 | * |
||
354 | * @param string $owner Repository owner. |
||
355 | * @param string $repo Repository name. |
||
356 | * |
||
357 | * @return object |
||
358 | * |
||
359 | * @since 1.0 |
||
360 | */ |
||
361 | public function getListTeams($owner, $repo) |
||
371 | |||
372 | /** |
||
373 | * List Tags. |
||
374 | * |
||
375 | * @param string $owner Repository owner. |
||
376 | * @param string $repo Repository name. |
||
377 | * |
||
378 | * @return object |
||
379 | * |
||
380 | * @since 1.0 |
||
381 | */ |
||
382 | public function getListTags($owner, $repo) |
||
392 | |||
393 | /** |
||
394 | * List Branches. |
||
395 | * |
||
396 | * @param string $owner Repository owner. |
||
397 | * @param string $repo Repository name. |
||
398 | * |
||
399 | * @return object |
||
400 | * |
||
401 | * @since 1.0 |
||
402 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::getList() instead |
||
403 | */ |
||
404 | public function getListBranches($owner, $repo) |
||
408 | |||
409 | /** |
||
410 | * Get a Branch. |
||
411 | * |
||
412 | * @param string $owner Repository owner. |
||
413 | * @param string $repo Repository name. |
||
414 | * @param string $branch Branch name. |
||
415 | * |
||
416 | * @return object |
||
417 | * |
||
418 | * @since 1.0 |
||
419 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::get() instead |
||
420 | */ |
||
421 | public function getBranch($owner, $repo, $branch) |
||
425 | |||
426 | /** |
||
427 | * Delete a Repository. |
||
428 | * |
||
429 | * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required. |
||
430 | * |
||
431 | * @param string $owner Repository owner. |
||
432 | * @param string $repo Repository name. |
||
433 | * |
||
434 | * @return object |
||
435 | * |
||
436 | * @since 1.0 |
||
437 | */ |
||
438 | public function delete($owner, $repo) |
||
448 | } |
||
449 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.