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 Bidesh
04:18
created

BridgeMarathon   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 131
Duplicated Lines 30.53 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 68.63%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 15
lcom 1
cbo 4
dl 40
loc 131
ccs 35
cts 51
cp 0.6863
rs 10
c 3
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 1
A __destruct() 0 7 2
A getJobs() 0 14 3
A addJob() 9 9 2
A updateJob() 9 9 2
A removeJob() 9 9 2
A getJobList() 0 19 3

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
 * @package: chapi
4
 *
5
 * @author:  bthapaliya
6
 * @since:   2016-12-02
7
 */
8
9
namespace Chapi\Service\JobRepository;
10
11
12
use Chapi\Component\Cache\CacheInterface;
13
use Chapi\Component\RemoteClients\ApiClientInterface;
14
use Chapi\Entity\Chronos\ChronosJobEntity;
15
use Chapi\Entity\JobEntityInterface;
16
use Chapi\Entity\Marathon\MarathonAppEntity;
17
use Chapi\Service\JobValidator\JobValidatorServiceInterface;
18
use Psr\Log\LoggerInterface;
19
20
class BridgeMarathon implements BridgeInterface
21
{
22
    const CACHE_TIME_JOB_LIST = 60;
23
24
    const CACHE_KEY_APP_LIST = 'marathon.app.list';
25
26
    /**
27
     * @var \Chapi\Component\RemoteClients\ApiClientInterface
28
     */
29
    private $oApiClient;
30
    /**
31
     * @var JobValidatorServiceInterface
32
     */
33
    private $oJobEntityValidatorService;
34
    /**
35
     * @var CacheInterface
36
     */
37
    private $oCache;
38
    /**
39
     * @var LoggerInterface
40
     */
41
    private $oLogger;
42
43
    private $bCacheHasToDelete = false;
44
45 5 View Code Duplication
    public function __construct(
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...
46
        ApiClientInterface $oApiClient,
47
        CacheInterface $oCache,
48
        JobValidatorServiceInterface $oJobEntityValidatorService,
49
        LoggerInterface $oLogger
50
    )
51
    {
52
53 5
        $this->oApiClient = $oApiClient;
54 5
        $this->oJobEntityValidatorService = $oJobEntityValidatorService;
55 5
        $this->oCache = $oCache;
56 5
        $this->oLogger = $oLogger;
57 5
    }
58
59 5
    public function __destruct()
60
    {
61 5
        if ($this->bCacheHasToDelete)
62 5
        {
63 2
            $this->oCache->delete(self::CACHE_KEY_APP_LIST);
64 2
        }
65 5
    }
66
67
    /**
68
     * @return JobEntityInterface[]
69
     */
70 1
    public function getJobs()
71
    {
72 1
        $_aApps = [];
73 1
        $_aJobsList = $this->getJobList();
74
75 1
        if (!empty($_aJobsList))
76 1
        {
77
            foreach ($_aJobsList as $_aJobData)
78
            {
79
                $_aApps[] = new MarathonAppEntity($_aJobData);
80
            }
81
        }
82 1
        return $_aApps;
83
    }
84
85
    /**
86
     * @param JobEntityInterface $oJobEntity
87
     * @return bool
88
     */
89 2 View Code Duplication
    public function addJob(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...
90
    {
91 2
        if ($this->oApiClient->addingJob($oJobEntity))
92 2
        {
93 1
            $this->bCacheHasToDelete = true;
94 1
            return true;
95
        }
96 1
        return false;
97
    }
98
99
    /**
100
     * @param JobEntityInterface $oJobEntity
101
     * @return bool
102
     */
103 View Code Duplication
    public function updateJob(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...
104
    {
105
        if ($this->oApiClient->updatingJob($oJobEntity))
106
        {
107
            $this->bCacheHasToDelete = true;
108
            return true;
109
        }
110
        return false;
111
    }
112
113
    /**
114
     * @param JobEntityInterface $oJobEntity
115
     * @return bool
116
     */
117 2 View Code Duplication
    public function removeJob(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...
118
    {
119 2
        if ($this->oApiClient->removeJob($oJobEntity->getKey()))
120 2
        {
121 1
            $this->bCacheHasToDelete = true;
122 1
            return true;
123
        }
124 1
        return false;
125
    }
126
127
    /**
128
     * @return array|mixed
129
     */
130 1
    private function getJobList()
131
    {
132 1
        $_aResult = $this->oCache->get(self::CACHE_KEY_APP_LIST);
133
134 1
        if (is_array($_aResult))
135 1
        {
136 1
            return $_aResult;
137
        }
138
139
        $_aResult = $this->oApiClient->listingJobs();
140
141
        if (!empty($_aResult['apps']))
142
        {
143
            $this->oCache->set(self::CACHE_KEY_APP_LIST, $_aResult['apps'], self::CACHE_TIME_JOB_LIST);
144
        }
145
146
        return $_aResult['apps'];
147
148
    }
149
150
}