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 (#158)
by Bernardo Vieira da
12:24
created

JobStatus::__construct()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7.049

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 10
cp 0.9
rs 8.8333
c 0
b 0
f 0
cc 7
nc 64
nop 1
crap 7.049
1
<?php
2
3
/**
4
 * Gearman Bundle for Symfony2
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 */
13
14
namespace Mmoreram\GearmanBundle\Module;
15
16
/**
17
 * Job status class
18
 *
19
 * @since 2.3.1
20
 */
21
class JobStatus
22
{
23
    /**
24
     * @var boolean
25
     *
26
     * Job is known
27
     */
28
    private $known;
29
30
    /**
31
     * @var boolean
32
     *
33
     * Job is running
34
     */
35
    private $running;
36
37
    /**
38
     * @var Integer
39
     *
40
     * Job completition
41
     */
42
    private $completed;
43
44
    /**
45
     * @var integer
46
     *
47
     * Job completition total
48
     */
49
    private $completionTotal;
50
51
    /**
52
     * Construct method
53
     *
54
     * @param array $response Response to parse
55
     */
56 4
    public function __construct(array $response)
57
    {
58 4
        $this->known = (isset($response[0]) && $response[0]);
59 4
        $this->running = (isset($response[1]) && $response[1]);
60
61 4
        $this->completed = (isset($response[2]) && !$response[2])
62 1
            ? 0
63 3
            : $response[2];
64
65 4
        $this->completionTotal = (isset($response[3]) && !$response[3])
66
            ? 0
67 4
            : $response[3];
68 4
    }
69
70
    /**
71
     * Return if job is known
72
     *
73
     * @return boolean Job is still known
74
     */
75 4
    public function isKnown()
76
    {
77 4
        return $this->known;
78
    }
79
80
    /**
81
     * Return if job is still running
82
     *
83
     * @return boolean Jon is still running
84
     */
85 4
    public function isRunning()
86
    {
87 4
        return $this->running;
88
    }
89
90
    /**
91
     * Return completed value
92
     *
93
     * @return integer Completed
94
     */
95 4
    public function getCompleted()
96
    {
97 4
        return $this->completed;
98
    }
99
100
    /**
101
     * Return completition total
102
     *
103
     * @return integer Completition total
104
     */
105 4
    public function getCompletionTotal()
106
    {
107 4
        return $this->completionTotal;
108
    }
109
110
    /**
111
     * Return percent completed.
112
     *
113
     * 0 is not started or not known
114
     * 1 is finished
115
     * Between 0 and 1 is in process. Value is a float
116
     *
117
     * @return float Percent completed
118
     */
119 4
    public function getCompletionPercent()
120
    {
121 4
        $percent = 0;
122
123 4
        if (($this->completed > 0) && ($this->completionTotal > 0)) {
124
125 2
            $percent = $this->completed / $this->completionTotal;
126
        }
127
128 4
        return $percent;
129
    }
130
131
    /**
132
     * Return if job is still running
133
     *
134
     * @return boolean Jon is still running
135
     */
136 4
    public function isFinished()
137
    {
138 4
        return $this->isKnown() && !$this->isRunning() && $this->getCompletionPercent() == 1;
139
    }
140
}
141