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 |
||
21 | class Commits extends AbstractPackage |
||
22 | { |
||
23 | /** |
||
24 | * List commits on a repository. |
||
25 | * |
||
26 | * A special note on pagination: Due to the way Git works, commits are paginated based on SHA |
||
27 | * instead of page number. |
||
28 | * Please follow the link headers as outlined in the pagination overview instead of constructing |
||
29 | * page links yourself. |
||
30 | * |
||
31 | * @param string $user The name of the owner of the GitHub repository. |
||
32 | * @param string $repo The name of the GitHub repository. |
||
33 | * @param string $sha Sha or branch to start listing commits from. |
||
34 | * @param string $path Only commits containing this file path will be returned. |
||
35 | * @param string $author GitHub login, name, or email by which to filter by commit author. |
||
36 | * @param \DateTime $since ISO 8601 Date - Only commits after this date will be returned. |
||
37 | * @param \DateTime $until ISO 8601 Date - Only commits before this date will be returned. |
||
38 | * |
||
39 | * @return object |
||
40 | * |
||
41 | * @since 1.0 |
||
42 | * @throws \DomainException |
||
43 | */ |
||
44 | public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTime $since = null, \DateTime $until = null) |
||
58 | |||
59 | /** |
||
60 | * Get a single commit. |
||
61 | * |
||
62 | * @param string $user The name of the owner of the GitHub repository. |
||
63 | * @param string $repo The name of the GitHub repository. |
||
64 | * @param string $sha The SHA of the commit to retrieve. |
||
65 | * |
||
66 | * @return object |
||
67 | * |
||
68 | * @since 1.0 |
||
69 | * @throws \DomainException |
||
70 | */ |
||
71 | public function get($user, $repo, $sha) |
||
79 | |||
80 | /** |
||
81 | * Get the SHA-1 of a commit reference. |
||
82 | * |
||
83 | * @param string $user The name of the owner of the GitHub repository. |
||
84 | * @param string $repo The name of the GitHub repository. |
||
85 | * @param string $ref The commit reference |
||
86 | * |
||
87 | * @return string |
||
88 | * |
||
89 | * @since 1.4.0 |
||
90 | * @throws UnexpectedResponseException |
||
91 | */ |
||
92 | public function getSha($user, $repo, $ref) |
||
111 | |||
112 | /** |
||
113 | * Compare two commits. |
||
114 | * |
||
115 | * @param string $user The name of the owner of the GitHub repository. |
||
116 | * @param string $repo The name of the GitHub repository. |
||
117 | * @param string $base The base of the diff, either a commit SHA or branch. |
||
118 | * @param string $head The head of the diff, either a commit SHA or branch. |
||
119 | * |
||
120 | * @return object |
||
121 | * |
||
122 | * @since 1.0 |
||
123 | */ |
||
124 | public function compare($user, $repo, $base, $head) |
||
134 | } |
||
135 |
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.