Deployments   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 7.53 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 7
loc 93
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createDeployement() 0 16 1
A listDeploymentStatus() 0 5 1
A createDeploymentStatus() 0 10 1
A listDeployments() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

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
2
namespace FlexyProject\GitHub\Receiver\Repositories;
3
4
use FlexyProject\GitHub\AbstractApi;
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * The Deployments API class provides access to repository's deployments.
9
 *
10
 * @link    https://developer.github.com/v3/repos/deployments/
11
 * @package FlexyProject\GitHub\Receiver\Repositories
12
 */
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,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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,
52
                                      array $requiredContexts = [], string $payload = '',
53
                                      string $environment = AbstractApi::ENVIRONMENT_PRODUCTION,
54
                                      string $description = ''): array
55
    {
56
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments',
57
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo()), Request::METHOD_POST, [
58
                'ref'               => $ref,
59
                'task'              => $task,
60
                'auto_merge'        => $autoMerge,
61
                'required_contexts' => $requiredContexts,
62
                'payload'           => $payload,
63
                'environment'       => $environment,
64
                'description'       => $description
65
            ]);
66
    }
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
78
    {
79
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments/:id/statuses',
80
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $id));
81
    }
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 = '',
96
                                           string $description = ''): array
97
    {
98
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments/:id/statuses',
99
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $id), Request::METHOD_POST, [
100
                'state'       => $state,
101
                'target_url'  => $targetUrl,
102
                'description' => $description
103
            ]);
104
    }
105
}