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 |
||
24 | class Events extends AbstractPackage |
||
25 | { |
||
26 | /** |
||
27 | * List events for an issue. |
||
28 | * |
||
29 | * @param string $owner The name of the owner of the GitHub repository. |
||
30 | * @param string $repo The name of the GitHub repository. |
||
31 | * @param integer $issueNumber The issue number. |
||
32 | * @param integer $page The page number from which to get items. |
||
33 | * @param integer $limit The number of items on a page. |
||
34 | * |
||
35 | * @return object |
||
36 | */ |
||
37 | View Code Duplication | public function getList($owner, $repo, $issueNumber, $page = 0, $limit = 0) |
|
|
|||
38 | { |
||
39 | // Build the request path. |
||
40 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueNumber . '/events'; |
||
41 | |||
42 | // Send the request. |
||
43 | return $this->processResponse( |
||
44 | $this->client->get($this->fetchUrl($path, $page, $limit)) |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * List events for a repository. |
||
50 | * |
||
51 | * @param string $owner The name of the owner of the GitHub repository. |
||
52 | * @param string $repo The name of the GitHub repository. |
||
53 | * @param integer $issueId The issue number. |
||
54 | * @param integer $page The page number from which to get items. |
||
55 | * @param integer $limit The number of items on a page. |
||
56 | * |
||
57 | * @return object |
||
58 | */ |
||
59 | public function getListRepository($owner, $repo, $issueId, $page = 0, $limit = 0) |
||
69 | |||
70 | /** |
||
71 | * Get a single event. |
||
72 | * |
||
73 | * @param string $owner The name of the owner of the GitHub repository. |
||
74 | * @param string $repo The name of the GitHub repository. |
||
75 | * @param integer $id The event number. |
||
76 | * |
||
77 | * @return object |
||
78 | */ |
||
79 | public function get($owner, $repo, $id) |
||
89 | } |
||
90 |
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.