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::listingJobs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.032
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