1 | <?php |
||
11 | class JobMonitor |
||
12 | { |
||
13 | /** |
||
14 | * Job name as configured in Jenkins |
||
15 | * @var string |
||
16 | */ |
||
17 | private $jobName; |
||
18 | |||
19 | /** |
||
20 | * The name to be displayed rather than the build number |
||
21 | * @var string |
||
22 | */ |
||
23 | private $displayName; |
||
24 | |||
25 | /** |
||
26 | * Long description of the build |
||
27 | * @var string |
||
28 | */ |
||
29 | private $description; |
||
30 | |||
31 | /** |
||
32 | * When the job was started running, in milliseconds |
||
33 | * @var integer |
||
34 | */ |
||
35 | private $startedOn; |
||
36 | |||
37 | /** |
||
38 | * Returns total duration of job execution, in milliseconds |
||
39 | * @var int |
||
40 | */ |
||
41 | private $duration; |
||
42 | |||
43 | /** |
||
44 | * Integer indicating the error code. 0 is success and everything else is failure |
||
45 | * @var integer |
||
46 | */ |
||
47 | private $exitCode; |
||
48 | |||
49 | /** |
||
50 | * Build log |
||
51 | * @var string |
||
52 | */ |
||
53 | private $log; |
||
54 | |||
55 | /** |
||
56 | * JobMonitor constructor. |
||
57 | * @param string $jobName |
||
58 | * @param string $displayName |
||
59 | * @param string $description |
||
60 | */ |
||
61 | 18 | public function __construct($jobName, $displayName = null, $description = null) |
|
70 | |||
71 | /** |
||
72 | * Starts job monitoring |
||
73 | */ |
||
74 | 15 | public function start() |
|
79 | |||
80 | /** |
||
81 | * Stops job monitoring |
||
82 | * @param string $exitCode |
||
83 | * @param string $log if log is provided, existing log data will be overwritten |
||
84 | * @see setLog |
||
85 | * @see appendLog |
||
86 | */ |
||
87 | 15 | public function stop($exitCode, $log = null) |
|
96 | |||
97 | /** |
||
98 | * @param int $exitCode |
||
99 | */ |
||
100 | 15 | public function setExitCode($exitCode) |
|
104 | |||
105 | /** |
||
106 | * Returns exit code |
||
107 | * @return int |
||
108 | */ |
||
109 | 3 | public function getExitCode() |
|
113 | |||
114 | /** |
||
115 | * Returns true only and only this job is completed |
||
116 | * @return boolean |
||
117 | */ |
||
118 | 12 | public function isCompleted() |
|
122 | |||
123 | /** |
||
124 | * Returns true only and only this job is completed and successfull |
||
125 | * @return boolean |
||
126 | */ |
||
127 | 3 | public function isSuccessful() |
|
131 | |||
132 | /** |
||
133 | * @param integer $duration Duration in milliseconds |
||
134 | */ |
||
135 | 15 | public function setDuration($duration) |
|
139 | |||
140 | /** |
||
141 | * Returns total duration of job execution, in milliseconds |
||
142 | * @return integer |
||
143 | */ |
||
144 | 9 | public function getDuration() |
|
148 | |||
149 | /** |
||
150 | * @param $log |
||
151 | */ |
||
152 | 9 | public function setLog($log) |
|
156 | |||
157 | /** |
||
158 | * Resets logs to empty string |
||
159 | */ |
||
160 | 18 | public function clearLog() |
|
164 | |||
165 | /** |
||
166 | * Appends provided log information to existing log |
||
167 | * @param $log |
||
168 | */ |
||
169 | 3 | public function appendLog($log) |
|
173 | |||
174 | /** |
||
175 | * Returns the log of this job |
||
176 | * @return string |
||
177 | */ |
||
178 | 3 | public function getLog() |
|
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | 9 | private function getRequestBody() |
|
206 | |||
207 | /** |
||
208 | * Constructs and returns the URI, where the monitor data must sent |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | 9 | private function getRequestUri() |
|
216 | |||
217 | /** |
||
218 | * Constructs and returns the Monitor request to be to Jenkins |
||
219 | * |
||
220 | * @return Psr\Http\Message\RequestInterface |
||
221 | */ |
||
222 | 9 | public function getRequest() |
|
226 | } |
||
227 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.