GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#68)
by Marc
06:49
created

MarathonApiClient   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 31.91 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 89.66%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 30
loc 94
ccs 26
cts 29
cp 0.8966
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addingJob() 7 7 1
A updatingJob() 7 7 1
A removeJob() 0 7 1
A getJobStats() 0 4 1
A listingJobs() 0 10 2
A ping() 16 16 4

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
3
namespace Chapi\Component\RemoteClients;
4
5
6
use Chapi\Component\Http\HttpClientInterface;
7
use Chapi\Entity\Chronos\ChronosJobEntity;
8
use Chapi\Entity\JobEntityInterface;
9
use Chapi\Exception\HttpConnectionException;
10
use Symfony\Component\Config\Definition\Exception\Exception;
11
12
class MarathonApiClient implements ApiClientInterface
13
{
14
15
    /** @var HttpClientInterface  */
16
    private $oHttpClient;
17
18 9
    public function __construct(
19
        HttpClientInterface $oHttpClient
20
    )
21
    {
22 9
        $this->oHttpClient = $oHttpClient;
23 9
    }
24
25
    /**
26
     * @link: https://mesos.github.io/chronos/docs/api.html#listing-jobs
27
     * @return array
28
     */
29 1
    public function listingJobs()
30
    {
31 1
        $oResponse = $this->oHttpClient->get('/v2/apps');
32 1
        if (200 == $oResponse->getStatusCode())
33
        {
34 1
            return $oResponse->json();
35
        }
36
37
        return [];
38
    }
39
40
    /**
41
     * @param JobEntityInterface $oJobEntity
42
     * @return bool
43
     */
44 1 View Code Duplication
    public function addingJob(JobEntityInterface $oJobEntity)
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...
45
    {
46 1
        $_sTargetEndpoint = '/v2/apps';
47
48 1
        $_oResponse = $this->oHttpClient->postJsonData($_sTargetEndpoint, $oJobEntity);
49 1
        return ($_oResponse->getStatusCode() == 201);
50
    }
51
52
    /**
53
     * @param JobEntityInterface|ChronosJobEntity $oJobEntity
54
     * @return bool
55
     */
56 1 View Code Duplication
    public function updatingJob(JobEntityInterface $oJobEntity)
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...
57
    {
58 1
        $_sTargetEndpoint = '/v2/apps';
59
60 1
        $_oResponse = $this->oHttpClient->putJsonData($_sTargetEndpoint, $oJobEntity);
61 1
        return ($_oResponse->getStatusCode() == 200);
62
    }
63
64
    /**
65
     * @param string $sJobName
66
     * @return bool
67
     */
68 1
    public function removeJob($sJobName)
69
    {
70 1
        $_sTargetEndpoint = '/v2/apps/'.$sJobName;
71
72 1
        $_oResponse = $this->oHttpClient->delete($_sTargetEndpoint);
73 1
        return ($_oResponse->getStatusCode() == 200);
74
    }
75
76
    /**
77
     * @param string $sJobName
78
     * @return array
79
     */
80
    public function getJobStats($sJobName)
81
    {
82
        return [];
83
    }
84
85
    /**
86
     * Returns true if the client can be connected to.
87
     * @return bool
88
     */
89 5 View Code Duplication
    public function ping()
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...
90
    {
91
        try {
92 5
            $this->oHttpClient->get('/v2/info');
93 4
        } catch (HttpConnectionException $e)
94
        {
95
            if (
96 4
                $e->getCode() == HttpConnectionException::ERROR_CODE_REQUEST_EXCEPTION ||
97 4
                $e->getCode() == HttpConnectionException::ERROR_CODE_CONNECT_EXCEPTION
98
            )
99
            {
100 2
                return false;
101
            }
102
        }
103 3
        return true;
104
    }
105
}