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 (#75)
by Bidesh
03:08
created

MarathonApiClient   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 16.84 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 16
loc 95
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 6 1
A listingJobs() 0 10 2
A addingJob() 0 7 1
A updatingJob() 0 8 1
A removeJob() 0 7 1
A getJobStats() 0 4 1
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
    public function addingJob(JobEntityInterface $oJobEntity)
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
    public function updatingJob(JobEntityInterface $oJobEntity)
57
    {
58 1
        $_sJobName = $oJobEntity->getKey();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
59 1
        $_sTargetEndpoint = '/v2/apps/' . $_sJobName;
60
61 1
        $_oResponse = $this->oHttpClient->putJsonData($_sTargetEndpoint, $oJobEntity);
62 1
        return ($_oResponse->getStatusCode() == 200);
63
    }
64
65
    /**
66
     * @param string $sJobName
67
     * @return bool
68
     */
69 1
    public function removeJob($sJobName)
70
    {
71 1
        $_sTargetEndpoint = '/v2/apps/' . $sJobName;
72
73 1
        $_oResponse = $this->oHttpClient->delete($_sTargetEndpoint);
74 1
        return ($_oResponse->getStatusCode() == 200);
75
    }
76
77
    /**
78
     * @param string $sJobName
79
     * @return array
80
     */
81
    public function getJobStats($sJobName)
82
    {
83
        return [];
84
    }
85
86
    /**
87
     * Returns true if the client can be connected to.
88
     * @return bool
89
     */
90 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...
91
    {
92
        try {
93 5
            $this->oHttpClient->get('/v2/info');
94 4
        } catch (HttpConnectionException $e)
95
        {
96
            if (
97 4
                $e->getCode() == HttpConnectionException::ERROR_CODE_REQUEST_EXCEPTION ||
98 4
                $e->getCode() == HttpConnectionException::ERROR_CODE_CONNECT_EXCEPTION
99
            )
100
            {
101 2
                return false;
102
            }
103
        }
104 3
        return true;
105
    }
106
}