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 |
||
| 25 | class Downloads extends AbstractPackage |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * List downloads for a repository. |
||
| 29 | * |
||
| 30 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 31 | * @param string $repo The name of the GitHub repository. |
||
| 32 | * |
||
| 33 | * @return object |
||
| 34 | * |
||
| 35 | * @since 1.0 |
||
| 36 | * @deprecated The Releases API should be used instead |
||
| 37 | */ |
||
| 38 | public function getList($owner, $repo) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get a single download. |
||
| 51 | * |
||
| 52 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 53 | * @param string $repo The name of the GitHub repository. |
||
| 54 | * @param integer $id The id of the download. |
||
| 55 | * |
||
| 56 | * @return object |
||
| 57 | * |
||
| 58 | * @since 1.0 |
||
| 59 | * @deprecated The Releases API should be used instead |
||
| 60 | */ |
||
| 61 | public function get($owner, $repo, $id) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Create a new download (Part 1: Create the resource). |
||
| 74 | * |
||
| 75 | * Creating a new download is a two step process. You must first create a new download resource. |
||
| 76 | * |
||
| 77 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 78 | * @param string $repo The name of the GitHub repository. |
||
| 79 | * @param string $name The name. |
||
| 80 | * @param string $size Size of file in bytes. |
||
| 81 | * @param string $description The description. |
||
| 82 | * @param string $content_type The content type. |
||
| 83 | * |
||
| 84 | * @return boolean |
||
| 85 | * |
||
| 86 | * @note This API endpoint no longer exists at GitHub |
||
| 87 | * @since 1.0 |
||
| 88 | * @throws \RuntimeException |
||
| 89 | * @deprecated The Releases API should be used instead |
||
| 90 | */ |
||
| 91 | public function create($owner, $repo, $name, $size, $description = '', $content_type = '') |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Create a new download (Part 2: Upload file to s3). |
||
| 98 | * |
||
| 99 | * Now that you have created the download resource, you can use the information |
||
| 100 | * in the response to upload your file to s3. This can be done with a POST to |
||
| 101 | * the s3_url you got in the create response. Here is a brief example using curl: |
||
| 102 | * |
||
| 103 | * curl \ |
||
| 104 | * -F "key=downloads/octocat/Hello-World/new_file.jpg" \ |
||
| 105 | * -F "acl=public-read" \ |
||
| 106 | * -F "success_action_status=201" \ |
||
| 107 | * -F "Filename=new_file.jpg" \ |
||
| 108 | * -F "AWSAccessKeyId=1ABCDEF..." \ |
||
| 109 | * -F "Policy=ewogIC..." \ |
||
| 110 | * -F "Signature=mwnF..." \ |
||
| 111 | * -F "Content-Type=image/jpeg" \ |
||
| 112 | * -F "file=@new_file.jpg" \ |
||
| 113 | * https://github.s3.amazonaws.com/ |
||
| 114 | * |
||
| 115 | * NOTES |
||
| 116 | * The order in which you pass these fields matters! Follow the order shown above exactly. |
||
| 117 | * All parameters shown are required and if you excluded or modify them your upload will |
||
| 118 | * fail because the values are hashed and signed by the policy. |
||
| 119 | * |
||
| 120 | * More information about using the REST API to interact with s3 can be found here: |
||
| 121 | * http://docs.amazonwebservices.com/AmazonS3/latest/API/ |
||
| 122 | * |
||
| 123 | * @param string $key Value of path field in the response. |
||
| 124 | * @param string $acl Value of acl field in the response. |
||
| 125 | * @param string $success_action_status 201, or whatever you want to get back. |
||
| 126 | * @param string $filename Value of name field in the response. |
||
| 127 | * @param string $awsAccessKeyId Value of accesskeyid field in the response. |
||
| 128 | * @param string $policy Value of policy field in the response. |
||
| 129 | * @param string $signature Value of signature field in the response. |
||
| 130 | * @param string $content_type Value of mime_type field in the response. |
||
| 131 | * @param string $file Local file. Example assumes the file existing in the directory |
||
| 132 | * where you are running the curl command. Yes, the @ matters. |
||
| 133 | * |
||
| 134 | * @return boolean |
||
| 135 | * |
||
| 136 | * @note This API endpoint no longer exists at GitHub |
||
| 137 | * @since 1.0 |
||
| 138 | * @throws \RuntimeException |
||
| 139 | * @deprecated The Releases API should be used instead |
||
| 140 | */ |
||
| 141 | public function upload($key, $acl, $success_action_status, $filename, $awsAccessKeyId, $policy, $signature, $content_type, $file) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Delete a download. |
||
| 148 | * |
||
| 149 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 150 | * @param string $repo The name of the GitHub repository. |
||
| 151 | * @param integer $id The id of the download. |
||
| 152 | * |
||
| 153 | * @return object |
||
| 154 | * |
||
| 155 | * @since 1.0 |
||
| 156 | * @deprecated The Releases API should be used instead |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function delete($owner, $repo, $id) |
|
| 169 | } |
||
| 170 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.