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 |
||
20 | View Code Duplication | class Commits extends AbstractPackage |
|
|
|||
21 | { |
||
22 | /** |
||
23 | * Get a Commit. |
||
24 | * |
||
25 | * @param string $owner The name of the owner of the GitHub repository. |
||
26 | * @param string $repo The name of the GitHub repository. |
||
27 | * @param string $sha The commit SHA. |
||
28 | * |
||
29 | * @return object |
||
30 | */ |
||
31 | public function get($owner, $repo, $sha) |
||
40 | |||
41 | /** |
||
42 | * Create a Commit. |
||
43 | * |
||
44 | * @param string $owner The name of the owner of the GitHub repository. |
||
45 | * @param string $repo The name of the GitHub repository. |
||
46 | * @param string $message The commit message. |
||
47 | * @param string $tree SHA of the tree object this commit points to. |
||
48 | * @param array $parents Array of the SHAs of the commits that were the parents of this commit. |
||
49 | * If omitted or empty, the commit will be written as a root commit. |
||
50 | * For a single parent, an array of one SHA should be provided. |
||
51 | * For a merge commit, an array of more than one should be provided. |
||
52 | * |
||
53 | * @since 1.0 |
||
54 | * |
||
55 | * @return object |
||
56 | */ |
||
57 | public function create($owner, $repo, $message, $tree, array $parents = array()) |
||
72 | } |
||
73 |
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.