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 (#96)
by Patrick
03:22 queued 59s
created

MarathonAppEntity::__construct()   C

Complexity

Conditions 11
Paths 129

Size

Total Lines 60
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 11.968

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 60
rs 5.8259
ccs 24
cts 30
cp 0.8
cc 11
eloc 34
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 48
    public function __construct($data = null)
88
    {
89 48
        if (!$data) {
90
            // initialized with default values
91 36
            return;
92
        }
93
94
        // make sure data is array
95 18
        $dataArray = (array) $data;
96
97 18
        MarathonEntityUtils::setAllPossibleProperties($dataArray, $this);
98
99 18
        if (isset($dataArray['portDefinitions'])) {
100
            foreach ($dataArray['portDefinitions'] as $portDefinition) {
101
                $this->portDefinitions[] = new PortDefinition((array) $portDefinition);
102
            }
103
        }
104
105 18
        if (isset($dataArray['container'])) {
106
            $this->container = new Container((array) $dataArray['container']);
107
        }
108
109 18
        if (isset($dataArray['healthChecks'])) {
110
            foreach ($dataArray['healthChecks'] as $healthCheck) {
111
                $this->healthChecks[] = new HealthCheck((array) $healthCheck);
112
            }
113
        }
114
115 18
        if (isset($dataArray['upgradeStrategy'])) {
116 1
            $this->upgradeStrategy = new UpgradeStrategy((array) $dataArray['upgradeStrategy']);
117
        } else {
118 18
            $this->upgradeStrategy = new UpgradeStrategy();
119
        }
120
121 18
        if (isset($dataArray['ipAddress'])) {
122
            $this->ipAddress = new IpAddress((array) $dataArray['ipAddress']);
123
        }
124
125 18
        if (isset($dataArray['env'])) {
126 1
            $env = (array) $dataArray['env'];
127
128 18
            // sorting this makes the diff output a whole lot more readable
129
            ksort($env);
130
131 18
            $this->env = (object) $env;
132 6
        } else {
133
            $this->env = (object) [];
134 13
        }
135
136 18
        if (isset($dataArray['labels'])) {
137 18
            $this->labels = (object) $dataArray['labels'];
138 18
        } else {
139 18
            $this->labels = (object) [];
140 18
        }
141 18
        MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'constraints');
142
        MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'args');
143
        MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'uris');
144
        MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'acceptedResourceRoles');
145
        MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'dependencies');
146
    }
147 4
148
    /**
149 4
     * @inheritdoc
150 4
     * @return array
151
     */
152 4 View Code Duplication
    public function jsonSerialize()
153 4
    {
154 4
        $return = (array) $this;
155 4
        $return = array_filter(
156
            $return,
157 4
            function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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...
158
                return !is_null($value) || empty($value);
159
            },
160
            ARRAY_FILTER_USE_BOTH
161
        );
162
        return $return;
163
    }
164 4
165
    /**
166 4
     * @inheritdoc
167
     * @return \ArrayIterator
168
     */
169
    public function getIterator()
170
    {
171
        return new \ArrayIterator($this);
172
    }
173 4
174
    /**
175 4
     * @inheritdoc
176
     * @return array
177 4
     */
178 4
    public function getSimpleArrayCopy()
179
    {
180
        $_aReturn = [];
181 4
182
        foreach ($this as $_sProperty => $mValue) {
183
            $_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue;
184
        }
185
186
        return $_aReturn;
187
    }
188
189
    /**
190
     * @inheritdoc
191
     * @return bool
192
     */
193
    public function isSchedulingJob()
194
    {
195
        return false;
196
    }
197 5
198
    /**
199 5
     * @inheritdoc
200
     * @return bool
201
     */
202
    public function isDependencyJob()
203
    {
204
        return count($this->dependencies) ? true : false;
205 5
    }
206
207 5
    /**
208
     * @return string
209
     */
210
    public function getEntityType()
211
    {
212
        return JobEntityInterface::MARATHON_TYPE;
213 27
    }
214
215 27
    /**
216
     * @return string
217
     */
218
    public function getKey()
219
    {
220
        return $this->id;
221
    }
222
}
223