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
Push — master ( a6590b...26125c )
by Marc
03:09
created

MarathonAppEntity::__construct()   C

Complexity

Conditions 11
Paths 129

Size

Total Lines 65
Code Lines 32

Duplication

Lines 12
Ratio 18.46 %

Code Coverage

Tests 24
CRAP Score 11.968

Importance

Changes 0
Metric Value
dl 12
loc 65
ccs 24
cts 30
cp 0.8
rs 5.5833
c 0
b 0
f 0
cc 11
eloc 32
nc 129
nop 1
crap 11.968

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\HealthCheck;
15
use Chapi\Entity\Marathon\AppEntity\IpAddress;
16
use Chapi\Entity\Marathon\AppEntity\PortDefinition;
17
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy;
18
19
class MarathonAppEntity implements JobEntityInterface
20
{
21
    public $id = '';
22
23
    public $cmd = null;
24
25
    public $cpus = 0;
26
27
    public $mem = 0;
28
29
    public $args = null;
30
31
    /**
32
     * @var PortDefinition[]
33
     */
34
    public $portDefinitions = null;
35
36
    public $requirePorts = false;
37
38
    public $instances = 0;
39
40
    public $executor = '';
41
42
    /**
43
     * @var Container
44
     */
45
    public $container = null;
46
47
    public $env = null;
48
49
    /**
50
     * @var array
51
     */
52
    public $constraints = [];
53
54
55
    public $acceptedResourceRoles = null;
56
57
    public $labels = null;
58
59
    public $uris = [];
60
61
    public $dependencies = [];
62
63
    /**
64
     * @var HealthCheck[]
65
     */
66
    public $healthChecks = null;
67
68
    public $backoffSeconds = 1;
69
70
    public $backoffFactor = 1.15;
71
72
    public $maxLaunchDelaySeconds = 3600;
73
74
    public $taskKillGracePeriodSeconds = 0;
75
76
    /**
77
     * @var UpgradeStrategy
78
     */
79
    public $upgradeStrategy = null;
80
81
82
    /**
83
     * @var IpAddress
84
     */
85
    public $ipAddress = null;
86
87 46
    public function __construct($mData = null)
88
    {
89 46
        if (!$mData)
90
        {
91
            // initialized with default values
92 34
            return;
93
        }
94
95
        // make sure data is array
96 18
        $aData = (array) $mData;
97
98 18
        MarathonEntityUtils::setAllPossibleProperties($aData, $this);
99
100 18
        if (isset($aData['portDefinitions']))
101
        {
102
            foreach ($aData['portDefinitions'] as $portDefinition)
103
            {
104
                $this->portDefinitions[] = new PortDefinition((array) $portDefinition);
105
            }
106
        }
107
108 18
        if (isset($aData['container']))
109
        {
110
            $this->container = new Container((array)$aData['container']);
111
        }
112
113 18
        if (isset($aData['healthChecks']))
114
        {
115
            foreach($aData['healthChecks'] as $healthCheck)
116
            {
117
                $this->healthChecks[] = new HealthCheck((array) $healthCheck);
118
            }
119
        }
120
121 18
        if (isset($aData['upgradeStrategy']))
122
        {
123 1
            $this->upgradeStrategy = new UpgradeStrategy((array) $aData['upgradeStrategy']);
124
        } else {
125 18
            $this->upgradeStrategy = new UpgradeStrategy();
126
        }
127
128 18
        if (isset($aData['ipAddress']))
129
        {
130
            $this->ipAddress = new IpAddress((array) $aData['ipAddress']);
131
        }
132
133 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...
134
        {
135 1
            $this->env =  (object) $aData['env'];
136
        } else {
137 18
            $this->env = (object) [];
138
        }
139
140 18 View Code Duplication
        if (isset($aData['labels']))
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...
141
        {
142 6
            $this->labels = (object) $aData['labels'];
143
        } else {
144 13
            $this->labels = (object) [];
145
        }
146 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'constraints');
147 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'args');
148 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'uris');
149 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'acceptedResourceRoles');
150 18
        MarathonEntityUtils::setPropertyIfExist($aData, $this, 'dependencies');
151 18
    }
152
153
    /**
154
     * @inheritdoc
155
     * @return array
156
     */
157 4 View Code Duplication
    public function jsonSerialize()
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...
158
    {
159 4
        $_aRet = (array) $this;
160 4
        $_aRet = array_filter(
161
            $_aRet,
162 4
            function($v, $k) {
0 ignored issues
show
Unused Code introduced by
The parameter $k is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
163 4
                return !is_null($v) || empty($v);
164 4
            },
165 4
            ARRAY_FILTER_USE_BOTH
166
        );
167 4
        return $_aRet;
168
    }
169
170
    /**
171
     * @inheritdoc
172
     * @return \ArrayIterator
173
     */
174 2
    public function getIterator()
175
    {
176 2
        return new \ArrayIterator($this);
177
    }
178
179
    /**
180
     * @inheritdoc
181
     * @return array
182
     */
183 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...
184
    {
185 2
        $_aReturn = [];
186
187 2
        foreach ($this as $_sProperty => $mValue)
188
        {
189 2
            $_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue;
190
        }
191
192 2
        return $_aReturn;
193
    }
194
195
    /**
196
     * @inheritdoc
197
     * @return bool
198
     */
199
    public function isSchedulingJob()
200
    {
201
        return false;
202
    }
203
204
    /**
205
     * @inheritdoc
206
     * @return bool
207
     */
208 5
    public function isDependencyJob()
209
    {
210 5
        return count($this->dependencies) ? true : false;
211
    }
212
213
    /**
214
     * @return string
215
     */
216 5
    public function getEntityType()
217
    {
218 5
        return JobEntityInterface::MARATHON_TYPE;
219
    }
220
221
    /**
222
     * @return string
223
     */
224 24
    public function getKey()
225
    {
226 24
        return $this->id;
227
    }
228
}