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.
Test Setup Failed
Push — master ( 74a7ac...f3a4fe )
by Caio
02:32
created

Runner::stop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Jamal\JenkinsArduino;
4
5
use Exception;
6
use Jamal\JenkinsArduino\Jenkins\Client;
7
use Jamal\JenkinsArduino\Jenkins\JobConfig;
8
use Jamal\JenkinsArduino\Jenkins\Credentials;
9
use Jamal\JenkinsArduino\Serial\Writer as SerialWriter;
10
use Jamal\JenkinsArduino\Serial\Detector;
11
use Jamal\JenkinsArduino\Jenkins\ArduinoFormatter;
12
use Jamal\JenkinsArduino\Http\Request;
13
use Jamal\JenkinsArduino\Validation\NotEmpty;
14
15
/**
16
 * @author Caio Almeida <[email protected]>
17
 */
18
class Runner
19
{
20
    /**
21
     * Roda a aplicação
22
     */
23
    public static function run()
24
    {
25
        $request = new Request();
26
27
        $job = $request->get('job');
28
29
        $validator = new NotEmpty('job', $job);
30
31
        if (!$validator->isValid()) {
32
            header("HTTP/1.1 422 Unprocessable Entity", true, 422);
33
            echo $validator->getMessage();
34
            self::stop();
35
        }
36
37
        $config = self::getConfig();
38
39
        $jobConfig = new JobConfig($job, $config['server'], $config['port']);
40
        $jobConfig->setCredentials(new Credentials());
41
42
        $client = new Client();
43
44
        $build = $client->doRequest($jobConfig);
45
46
        $formatter = new ArduinoFormatter();
47
        $data = $formatter->format($build);
48
49
        $usbDetector = new Detector();
50
        $usbArduino = $usbDetector->detect($config['serialType'], $config['serialCount']);
51
52
        $serialReader = new SerialWriter();
53
        $serialReader->write($usbArduino, $data);
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public static function getConfig()
60
    {
61
        $path = __DIR__ . '/../../config/production.php';
62
63
        if (!is_readable($path)) {
64
            throw new Exception('O arquivo de configuração production.php não existe!');
65
        }
66
67
        $config = include $path;
68
        return $config;
69
    }
70
71
    public static function stop()
72
    {
73
        die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method stop() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
74
    }
75
}
76