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 | class Trees extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Get a Tree |
||
| 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 SHA1 value to set the reference to. |
||
| 28 | * |
||
| 29 | * @since 1.0 |
||
| 30 | * |
||
| 31 | * @return object |
||
| 32 | */ |
||
| 33 | public function get($owner, $repo, $sha) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get a Tree Recursively |
||
| 45 | * |
||
| 46 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 47 | * @param string $repo The name of the GitHub repository. |
||
| 48 | * @param string $sha The SHA1 value to set the reference to. |
||
| 49 | * |
||
| 50 | * @since 1.0 |
||
| 51 | * |
||
| 52 | * @return object |
||
| 53 | */ |
||
| 54 | public function getRecursively($owner, $repo, $sha) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Create a Tree. |
||
| 66 | * |
||
| 67 | * The tree creation API will take nested entries as well. If both a tree and a nested path |
||
| 68 | * modifying that tree are specified, it will overwrite the contents of that tree with the |
||
| 69 | * new path contents and write a new tree out. |
||
| 70 | * |
||
| 71 | * Parameters fir the tree: |
||
| 72 | * |
||
| 73 | * tree.path |
||
| 74 | * String of the file referenced in the tree |
||
| 75 | * tree.mode |
||
| 76 | * String of the file mode - one of 100644 for file (blob), 100755 for executable (blob), |
||
| 77 | * 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob |
||
| 78 | * that specifies the path of a symlink |
||
| 79 | * tree.type |
||
| 80 | * String of blob, tree, commit |
||
| 81 | * tree.sha |
||
| 82 | * String of SHA1 checksum ID of the object in the tree |
||
| 83 | * tree.content |
||
| 84 | * String of content you want this file to have - GitHub will write this blob out and use |
||
| 85 | * that SHA for this entry. Use either this or tree.sha |
||
| 86 | * |
||
| 87 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 88 | * @param string $repo The name of the GitHub repository. |
||
| 89 | * @param array $tree Array of Hash objects (of path, mode, type and sha) specifying |
||
| 90 | * a tree structure |
||
| 91 | * @param string $base_tree The SHA1 of the tree you want to update with new data. |
||
| 92 | * |
||
| 93 | * @since 1.0 |
||
| 94 | * |
||
| 95 | * @return object |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function create($owner, $repo, $tree, $base_tree = '') |
|
| 116 | } |
||
| 117 |
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.