Statuses   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 18.97 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 11
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createStatus() 11 11 1
A listStatuses() 0 5 1
A getCombinedStatus() 0 5 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 Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Statuses API class provides access to repository's statuses.
8
 *
9
 * @link    https://developer.github.com/v3/repos/statuses/
10
 * @package FlexyProject\GitHub\Receiver\Repositories
11
 */
12
class Statuses extends AbstractRepositories
13
{
14
15
    /**
16
     * Create a Status
17
     *
18
     * @link https://developer.github.com/v3/repos/statuses/#create-a-status
19
     *
20
     * @param string $sha
21
     * @param string $state
22
     * @param string $targetUrl
23
     * @param string $description
24
     * @param string $context
25
     *
26
     * @return array
27
     */
28 View Code Duplication
    public function createStatus(string $sha, string $state, string $targetUrl = null, string $description = 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 $context = 'default'): array
30
    {
31
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/statuses/:sha',
32
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $sha), Request::METHOD_POST, [
33
                'state'       => $state,
34
                'target_url'  => $targetUrl,
35
                'description' => $description,
36
                'context'     => $context
37
            ]);
38
    }
39
40
    /**
41
     * List Statuses for a specific Ref
42
     *
43
     * @link https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
44
     *
45
     * @param string $ref
46
     *
47
     * @return array
48
     */
49
    public function listStatuses(string $ref): array
50
    {
51
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:ref/statuses',
52
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $ref));
53
    }
54
55
    /**
56
     * Get the combined Status for a specific Ref
57
     *
58
     * @link https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
59
     *
60
     * @param string $ref
61
     *
62
     * @return array
63
     */
64
    public function getCombinedStatus(string $ref): array
65
    {
66
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:ref/status',
67
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $ref));
68
    }
69
}