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.

MarathonApiClient   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 24.44 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 22
loc 90
ccs 27
cts 30
cp 0.9
rs 10
c 0
b 0
f 0

7 Methods

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