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

ChronosJobEntity   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 89.8%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 24
lcom 1
cbo 2
dl 0
loc 194
ccs 44
cts 49
cp 0.898
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSimpleArrayCopy() 0 10 4
A isSchedulingJob() 0 4 2
A isDependencyJob() 0 4 2
C __construct() 0 24 8
B jsonSerialize() 0 34 5
A getIterator() 0 4 1
A getEntityType() 0 4 1
A getKey() 0 4 1
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
    public $uris = [];
69
70
    /** @var FetchEntity[] */
71
    public $fetch = [];
72
73
    public $environmentVariables = [];
74
75
    public $arguments = [];
76
77
    public $highPriority = false;
78
79
    public $runAsUser = 'root';
80
81
    public $constraints = [];
82
83
    /** @var ContainerEntity */
84
    public $container = null;
85
86
87
    /**
88
     * @param array|object $jobData
89
     * @throws \InvalidArgumentException
90
     */
91 117
    public function __construct($jobData = [])
92
    {
93 117
        if (is_array($jobData) || is_object($jobData)) {
94 116
            foreach ($jobData as $key => $value) {
95 18
                if (property_exists($this, $key)) {
96 18
                    if ($key == 'container') {
97 2
                        $this->{$key} = new ContainerEntity($value);
98 18
                    } else if ($key == 'fetch') {
99 5
                        foreach ($value as $fetch) {
100 5
                            $this->{$key}[] = new FetchEntity($fetch);
101
                        }
102
                    } else {
103 18
                        $this->{$key} = $value;
104
                    }
105 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...
106
                    /* We are ignoring fields that are unknown to us. This is bad and can lead to unexpected differences
107
                     * when comparing the *.json on disk with the job definition from the Chronos API.
108
                     */
109
                }
110
            }
111
        } else {
112 1
            throw new \InvalidArgumentException(sprintf('Argument 1 passed to "%s" must be an array or object', __METHOD__));
113
        }
114 115
    }
115
116
    /**
117
     * return entity as one-dimensional array
118
     *
119
     * @return mixed[]
120
     */
121 8
    public function getSimpleArrayCopy()
122
    {
123 8
        $return = [];
124
125 8
        foreach ($this as $property => $value) {
126 8
            $return[$property] = (is_array($value) || is_object($value)) ? json_encode($value) : $value;
127
        }
128
129 8
        return $return;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135 18
    public function isSchedulingJob()
136
    {
137 18
        return (!empty($this->schedule) && empty($this->parents));
138
    }
139
140
    /**
141
     * @return bool
142
     */
143 7
    public function isDependencyJob()
144
    {
145 7
        return (empty($this->schedule) && !empty($this->parents));
146
    }
147
148
    /**
149
     * @return array
150
     */
151 11
    public function jsonSerialize()
152
    {
153 11
        $return = (array) $this;
154 11
        if (!empty($this->schedule)) {
155 10
            unset($return['parents']);
156
        } else {
157 1
            unset($return['schedule']);
158 1
            unset($return['scheduleTimeZone']);
159
        }
160
161 11
        if (empty($this->container)) {
162 11
            unset($return['container']);
163
        } else {
164
            $return['container'] = (array) $this->container;
165
166
            $return['container']['volumes'] = [];
167
            foreach ($this->container->volumes as $volume) {
168
                $return['container']['volumes'][] = (array) $volume;
169
            }
170
        }
171
172 11
        $return['fetch'] = [];
173 11
        foreach ($this->fetch as $fetch) {
174
            $return['fetch'][] = (array) $fetch;
175
        }
176
177 11
        unset($return['successCount']);
178 11
        unset($return['errorCount']);
179 11
        unset($return['errorsSinceLastSuccess']);
180 11
        unset($return['lastSuccess']);
181 11
        unset($return['lastError']);
182
183 11
        return $return;
184
    }
185
186
    /**
187
     * @return \ArrayIterator
188
     */
189 9
    public function getIterator()
190
    {
191 9
        return new \ArrayIterator($this);
192
    }
193
194
    /**
195
     * @return string
196
     */
197 5
    public function getEntityType()
198
    {
199 5
        return JobEntityInterface::CHRONOS_TYPE;
200
    }
201
202
    /**
203
     * @return string
204
     */
205 41
    public function getKey()
206
    {
207 41
        return $this->name;
208
    }
209
}
210