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 (#104)
by
unknown
06:19
created

MarathonAppEntity   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 205
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.73%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
lcom 1
cbo 2
dl 0
loc 205
ccs 51
cts 55
cp 0.9273
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 4 1
B __construct() 0 41 4
B jsonSerialize() 0 23 5
A getSimpleArrayCopy() 0 10 4
A isSchedulingJob() 0 4 1
A isDependencyJob() 0 4 2
A getEntityType() 0 4 1
A getKey() 0 4 1
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\Fetch;
15
use Chapi\Entity\Marathon\AppEntity\HealthCheck;
16
use Chapi\Entity\Marathon\AppEntity\IpAddress;
17
use Chapi\Entity\Marathon\AppEntity\Network;
18
use Chapi\Entity\Marathon\AppEntity\PortDefinition;
19
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy;
20
21
class MarathonAppEntity implements JobEntityInterface
22
{
23
    public $id = '';
24
25
    public $cmd = null;
26
27
    public $cpus = 0;
28
29
    public $mem = 0;
30
31
    public $args = null;
32
33
    /**
34
     * @var PortDefinition[]
35
     */
36
    public $portDefinitions = null;
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
    /**
50
     * @var Network[]
51
     */
52
    public $networks = [];
53
54
    public $env = null;
55
56
    /**
57
     * @var array
58
     */
59
    public $constraints = [];
60
61
    public $acceptedResourceRoles = null;
62
63
    public $labels = null;
64
65
    public $uris = [];
66
67
    /**
68
     * @var Fetch[]
69
     */
70
    public $fetch = [];
71
72
    public $dependencies = [];
73
74
    /**
75
     * @var HealthCheck[]
76
     */
77
    public $healthChecks = null;
78
79
    public $backoffSeconds = 1;
80
81
    public $backoffFactor = 1.15;
82
83
    public $maxLaunchDelaySeconds = 3600;
84
85
    public $taskKillGracePeriodSeconds = 0;
86
87
    /**
88
     * @var UpgradeStrategy
89
     */
90
    public $upgradeStrategy = null;
91
92
93
    /**
94
     * @var IpAddress
95
     */
96
    public $ipAddress = null;
97
98 52
    public function __construct($data = null)
99
    {
100 52
        if (!$data) {
101
            // initialized with default values
102 37
            return;
103
        }
104
105
        // make sure data is array
106 21
        $dataArray = (array) $data;
107
108 21
        MarathonEntityUtils::setAllPossibleProperties(
109 21
            $dataArray,
110 21
            $this,
111
            array(
112 21
                'portDefinitions' => MarathonEntityUtils::convArrayOfClass(PortDefinition::class),
113 21
                'container' => MarathonEntityUtils::convClass(Container::class),
114 21
                'networks' => MarathonEntityUtils::convArrayOfClass(Network::class),
115 21
                'fetch' => MarathonEntityUtils::convArrayOfClass(Fetch::class),
116 21
                'healthChecks' => MarathonEntityUtils::convArrayOfClass(HealthCheck::class),
117 21
                'upgradeStrategy' => MarathonEntityUtils::convClass(UpgradeStrategy::class),
118 21
                'ipAddress' => MarathonEntityUtils::convClass(IpAddress::class),
119 21
                'env' => MarathonEntityUtils::convSortedObject(),
120 21
                'labels' => MarathonEntityUtils::convSortedObject(),
121
122
                # don't skip assigning these just because they are arrays or objects in $dataArray
123 21
                'constraints' => MarathonEntityUtils::noConv(),
124 21
                'args' => MarathonEntityUtils::noConv(),
125 21
                'uris' => MarathonEntityUtils::noConv(),
126 21
                'acceptedResourceRoles' => MarathonEntityUtils::noConv(),
127 21
                'dependencies' => MarathonEntityUtils::noConv()
128
            )
129
        );
130
131 21
        if (!isset($dataArray['upgradeStrategy'])) {
132 21
            $this->upgradeStrategy = new UpgradeStrategy();
133
        }
134
135 21
        if (!isset($dataArray['labels'])) {
136 16
            $this->upgradeStrategy = (object) [];
137
        }
138 21
    }
139
140
    /**
141
     * @inheritdoc
142
     * @return array
143
     */
144 4
    public function jsonSerialize()
145
    {
146 4
        $return = (array) $this;
147
148
        // delete empty fields
149 4
        $return = array_filter(
150 4
            $return,
151 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...
152 4
                return !is_null($value) || empty($value);
153 4
            },
154 4
            ARRAY_FILTER_USE_BOTH // there is no ARRAY_FILTER_USE_VALUE
155
        );
156
157 4
        if (isset($return["networks"])
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal networks does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
158 4
            && count($return["networks"]) == 1 // you can only have one bridge or host network
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal networks does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
159 4
            && $return["networks"][0]->mode != "container")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal networks does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal container does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
160
        {
161
            $return["networks"][0] = (array) $return["networks"][0];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal networks does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
162
            unset($return["networks"][0]["name"]); // only "container" networks can have names
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal networks does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal name does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

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