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.

ChronosJobEntity::getSimpleArrayCopy()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 5
nop 0
crap 4
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-29
7
 *
8
 */
9
10
namespace Chapi\Entity\Chronos;
11
12
use Chapi\Entity\Chronos\JobEntity\ContainerEntity;
13
use Chapi\Entity\Chronos\JobEntity\FetchEntity;
14
use Chapi\Entity\JobEntityInterface;
15
16
class ChronosJobEntity implements JobEntityInterface
17
{
18
    public $name = '';
19
20
    public $command = '';
21
22
    public $description = '';
23
24
    public $owner = '';
25
26
    public $ownerName = '';
27
28
    public $schedule = ''; // todo: move to separate entity
29
30
    public $scheduleTimeZone = '';
31
32
    public $parents = []; // todo: move to separate entity
33
34
    public $epsilon = '';
35
36
    public $executor = '';
37
38
    public $executorFlags = '';
39
40
    public $shell = true;
41
42
    public $retries = 0;
43
44
    public $async = false;
45
46
    public $successCount = 0;
47
48
    public $errorCount = 0;
49
50
    public $errorsSinceLastSuccess = 0;
51
52
    public $lastSuccess = '';
53
54
    public $lastError = '';
55
56
    public $cpus = 0.1;
57
58
    public $disk = 24;
59
60
    public $mem = 32;
61
62
    public $disabled = false;
63
64
    public $softError = false;
65
66
    public $dataProcessingJobType = false;
67
68
    /** @var FetchEntity[] */
69
    public $fetch = [];
70
71
    public $environmentVariables = [];
72
73
    public $arguments = [];
74
75
    public $highPriority = false;
76
77
    public $runAsUser = 'root';
78
79
    public $constraints = [];
80
81
    /** @var ContainerEntity */
82
    public $container = null;
83
84
85
    /**
86
     * @param array|object $jobData
87
     * @throws \InvalidArgumentException
88
     */
89 117
    public function __construct($jobData = [])
90
    {
91 117
        if (is_array($jobData) || is_object($jobData)) {
92 116
            foreach ($jobData as $key => $value) {
93 18
                if (property_exists($this, $key)) {
94 18
                    if ($key == 'container') {
95 2
                        $this->{$key} = new ContainerEntity($value);
96 18
                    } else if ($key == 'fetch') {
97 6
                        foreach ($value as $fetch) {
98 6
                            $this->{$key}[] = new FetchEntity($fetch);
99
                        }
100
                    } else {
101 18
                        $this->{$key} = $value;
102
                    }
103 116
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
104
                    /* We are ignoring fields that are unknown to us. This is bad and can lead to unexpected differences
105
                     * when comparing the *.json on disk with the job definition from the Chronos API.
106
                     */
107
                }
108
            }
109
        } else {
110 1
            throw new \InvalidArgumentException(sprintf('Argument 1 passed to "%s" must be an array or object', __METHOD__));
111
        }
112 115
    }
113
114
    /**
115
     * return entity as one-dimensional array
116
     *
117
     * @return mixed[]
118
     */
119 8
    public function getSimpleArrayCopy()
120
    {
121 8
        $return = [];
122
123 8
        foreach ($this as $property => $value) {
124 8
            $return[$property] = (is_array($value) || is_object($value)) ? json_encode($value) : $value;
125
        }
126
127 8
        return $return;
128
    }
129
130
    /**
131
     * @return bool
132
     */
133 18
    public function isSchedulingJob()
134
    {
135 18
        return (!empty($this->schedule) && empty($this->parents));
136
    }
137
138
    /**
139
     * @return bool
140
     */
141 7
    public function isDependencyJob()
142
    {
143 7
        return (empty($this->schedule) && !empty($this->parents));
144
    }
145
146
    /**
147
     * @return array
148
     */
149 11
    public function jsonSerialize()
150
    {
151 11
        $return = (array) $this;
152 11
        if (!empty($this->schedule)) {
153 10
            unset($return['parents']);
154
        } else {
155 1
            unset($return['schedule']);
156 1
            unset($return['scheduleTimeZone']);
157
        }
158
159 11
        if (empty($this->container)) {
160 11
            unset($return['container']);
161
        } else {
162
            $return['container'] = (array) $this->container;
163
164
            $return['container']['volumes'] = [];
165
            foreach ($this->container->volumes as $volume) {
166
                $return['container']['volumes'][] = (array) $volume;
167
            }
168
        }
169
170 11
        $return['fetch'] = [];
171 11
        foreach ($this->fetch as $fetch) {
172
            $return['fetch'][] = (array) $fetch;
173
        }
174
175 11
        unset($return['successCount']);
176 11
        unset($return['errorCount']);
177 11
        unset($return['errorsSinceLastSuccess']);
178 11
        unset($return['lastSuccess']);
179 11
        unset($return['lastError']);
180
181 11
        return $return;
182
    }
183
184
    /**
185
     * @return \ArrayIterator
186
     */
187 9
    public function getIterator()
188
    {
189 9
        return new \ArrayIterator($this);
190
    }
191
192
    /**
193
     * @return string
194
     */
195 5
    public function getEntityType()
196
    {
197 5
        return JobEntityInterface::CHRONOS_TYPE;
198
    }
199
200
    /**
201
     * @return string
202
     */
203 41
    public function getKey()
204
    {
205 41
        return $this->name;
206
    }
207
}
208