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
02:54
created

MarathonAppEntity   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 198
Duplicated Lines 8.59 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 87.3%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 22
lcom 1
cbo 6
dl 17
loc 198
ccs 55
cts 63
cp 0.873
rs 10
c 4
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 6 60 11
A jsonSerialize() 0 5 1
A getIterator() 0 4 1
A getSimpleArrayCopy() 11 11 4
A isSchedulingJob() 0 4 1
A isDependencyJob() 0 4 2
A getEntityType() 0 4 1
A getKey() 0 4 1

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-10-16
7
 *
8
 */
9
10
namespace Chapi\Entity\Marathon;
11
12
use Chapi\Entity\JobEntityInterface;
13
use Chapi\Entity\Marathon\AppEntity\Container;
14
use Chapi\Entity\Marathon\AppEntity\DockerPortMapping;
15
use Chapi\Entity\Marathon\AppEntity\HealthCheck;
16
use Chapi\Entity\Marathon\AppEntity\IpAddress;
17
use Chapi\Entity\Marathon\AppEntity\PortDefinition;
18
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy;
19
use Symfony\Component\Config\Definition\Exception\Exception;
20
21
class MarathonAppEntity implements JobEntityInterface
22
{
23
    public $id = '';
24
25
    public $cmd = '';
26
27
    public $cpus = 0;
28
29
    public $mem = 0;
30
31
    public $args = [];
32
33
    /**
34
     * @var PortDefinition[]
35
     */
36
    public $portDefinitions =[];
37
38
    public $requirePorts = false;
39
40
    public $instances = 0;
41
42
    public $executor = '';
43
44
    /**
45
     * @var Container
46
     */
47
    public $container = null;
48
49
    public $env = null;
50
51
    /**
52
     * @var array
53
     */
54
    public $constraints  = [];
55
56
57
    public $acceptedResourceRoles = [];
58
59
    public $labels = null;
60
61
    public $uris = [];
62
63
    public $dependencies = [];
64
65
    /**
66
     * @var HealthCheck[]
67
     */
68
    public $healthChecks = [];
69
70
    public $backoffSeconds = 1;
71
72
    public $backoffFactor = 1.15;
73
74
    public $maxLaunchDelaySeconds = 3600;
75
76
    public $taskKillGracePeriodSeconds = 0;
77
78
    /**
79
     * @var UpgradeStrategy
80
     */
81
    public $upgradeStrategy = null;
82
83
84
    /**
85
     * @var IpAddress
86
     */
87
    public $ipAddress = null;
88
89 45
    public function __construct($mData = null)
90
    {
91 45
        if (!$mData)
92 45
        {
93
            // initialized with default values
94 33
            return;
95
        }
96
97
        // make sure data is array
98 18
        $aData = (array) $mData;
99
100 18
        MarathonEntityUtils::setAllPossibleProperties($aData, $this);
101
102 18
        if (isset($aData['portDefinitions'])) {
103 4
            foreach ($aData['portDefinitions'] as $portDefinition) {
104
                $this->portDefinitions[] = new PortDefinition((array)$portDefinition);
105 4
            }
106 4
        }
107
108 18
        if (isset($aData['container'])) {
109
            $this->container = new Container((array)$aData['container']);
110
        }
111
112 18
        if (isset($aData['healthChecks']))
113 18
        {
114 4
            foreach($aData['healthChecks'] as $healthCheck)
115
            {
116
                $this->healthChecks[] = new HealthCheck((array)$healthCheck);
117 4
            }
118 4
        }
119
120 18
        if (isset($aData['upgradeStrategy']))
121 18
        {
122 1
            $this->upgradeStrategy = new UpgradeStrategy((array)$aData['upgradeStrategy']);
123 1
        } else {
124 18
            $this->upgradeStrategy = new UpgradeStrategy();
125
        }
126
127 18
        if (isset($aData['ipAddress']))
128 18
        {
129
            $this->ipAddress = new IpAddress((array)$aData['ipAddress']);
130
        }
131
132 18 View Code Duplication
        if (isset($aData['env']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
133 18
        {
134 1
            $this->env =  (object) $aData['env'];
135 1
        } else {
136 18
            $this->env = (object)[];
137
        }
138
139 18
        if (isset($aData['labels']))
140 18
        {
141 5
            $this->labels = (object) $aData['labels'];
142 5
        }
143 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'constraints');
144 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'args');
145 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'uris');
146 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'acceptedResourceRoles');
147 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'dependencies');
148 18
    }
149
150
    /**
151
     * @inheritdoc
152
     * @return array
153
     */
154 4
    public function jsonSerialize()
155
    {
156 4
        $_aRet = (array) $this;
157 4
        return $_aRet;
158
    }
159
160
    /**
161
     * @inheritdoc
162
     * @return \ArrayIterator
163
     */
164 2
    public function getIterator()
165
    {
166 2
        return new \ArrayIterator($this);
167
    }
168
169
    /**
170
     * @inheritdoc
171
     * @return array
172
     */
173 2 View Code Duplication
    public function getSimpleArrayCopy()
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...
174
    {
175 2
        $_aReturn = [];
176
177 2
        foreach ($this as $_sProperty => $mValue)
178
        {
179 2
            $_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue;
180 2
        }
181
182 2
        return $_aReturn;
183
    }
184
185
    /**
186
     * @inheritdoc
187
     * @return bool
188
     */
189
    public function isSchedulingJob()
190
    {
191
        return false;
192
    }
193
194
    /**
195
     * @inheritdoc
196
     * @return bool
197
     */
198 5
    public function isDependencyJob()
199
    {
200 5
        return count($this->dependencies) ? true : false;
201
    }
202
203
    /**
204
     * @return string
205
     */
206 5
    public function getEntityType()
207
    {
208 5
        return JobEntityInterface::MARATHON_TYPE;
209
    }
210
211
    /**
212
     * @return string
213
     */
214 23
    public function getKey()
215
    {
216 23
        return $this->id;
217
    }
218
}