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 |
||
| 13 | class Deployments extends AbstractRepositories |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * List Deployments |
||
| 18 | * |
||
| 19 | * @link https://developer.github.com/v3/repos/deployments/#list-deployments |
||
| 20 | * |
||
| 21 | * @param string $sha |
||
| 22 | * @param string $ref |
||
| 23 | * @param string $task |
||
| 24 | * @param string $environment |
||
| 25 | * |
||
| 26 | * @return array |
||
| 27 | */ |
||
| 28 | View Code Duplication | public function listDeployments(string $sha = null, string $ref = null, string $task = null, |
|
|
|
|||
| 29 | string $environment = null): array |
||
| 30 | { |
||
| 31 | return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments', |
||
| 32 | $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), |
||
| 33 | http_build_query(['sha' => $sha, 'ref' => $ref, 'task' => $task, 'environment' => $environment]))); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Create a Deployment |
||
| 38 | * |
||
| 39 | * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment |
||
| 40 | * |
||
| 41 | * @param string $ref |
||
| 42 | * @param string $task |
||
| 43 | * @param bool $autoMerge |
||
| 44 | * @param array $requiredContexts |
||
| 45 | * @param string $payload |
||
| 46 | * @param string $environment |
||
| 47 | * @param string $description |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function createDeployement(string $ref, string $task = AbstractApi::TASK_DEPLOY, bool $autoMerge = true, |
||
| 67 | |||
| 68 | /** |
||
| 69 | * List Deployment Statuses |
||
| 70 | * |
||
| 71 | * @link https://developer.github.com/v3/repos/deployments/#list-deployment-statuses |
||
| 72 | * |
||
| 73 | * @param int $id |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function listDeploymentStatus(int $id): array |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Create a Deployment Status |
||
| 85 | * |
||
| 86 | * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status |
||
| 87 | * |
||
| 88 | * @param int $id |
||
| 89 | * @param string $state |
||
| 90 | * @param string $targetUrl |
||
| 91 | * @param string $description |
||
| 92 | * |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | public function createDeploymentStatus(int $id, string $state, string $targetUrl = '', |
||
| 105 | } |
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.