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 Failed
Push — master ( 44f5f8...8d9d8e )
by Anton
02:15
created

Server::start()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 0
loc 16
ccs 8
cts 12
cp 0.6667
crap 2.1481
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
4
namespace Deployer\Executor;
5
6
use Deployer\Deployer;
7
use Deployer\Exception\Exception;
8
use Deployer\Task\Context;
9
use Psr\Http\Message\ServerRequestInterface;
10
use React;
11
use React\Http\Message\Response;
12
use Symfony\Component\Console\Helper\QuestionHelper;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Throwable;
16
use function Deployer\getHost;
17
18
class Server
19
{
20
    private $input;
21
    private $output;
22
    private $questionHelper;
23
    private $loop;
24
    private $port;
25
26 10
    public function __construct(
27
        InputInterface $input,
28
        OutputInterface $output,
29
        QuestionHelper $questionHelper
30
    )
31
    {
32 10
        $this->input = $input;
33 10
        $this->output = $output;
34 10
        $this->questionHelper = $questionHelper;
35 10
    }
36
37 10
    public function start()
38
    {
39 10
        $this->loop = React\EventLoop\Factory::create();
40
        $server = new React\Http\Server($this->loop, function (ServerRequestInterface $request) {
41
            try {
42
                return $this->router($request);
43
            } catch (Throwable $exception) {
44
                Deployer::printException($this->output, $exception);
45
                return new React\Http\Message\Response(500, ['Content-Type' => 'text/plain'], 'Master error: ' . $exception->getMessage());
46
            }
47 10
        });
48 10
        $socket = new React\Socket\Server(0, $this->loop);
49 10
        $server->listen($socket);
50 10
        $address = $socket->getAddress();
51 10
        $this->port = parse_url($address, PHP_URL_PORT);
52 10
    }
53
54
    private function router(ServerRequestInterface $request): Response
55
    {
56
        switch ($request->getUri()->getPath()) {
57
            case '/proxy':
58
                $body = $request->getBody();
59
                ['host' => $host, 'func' => $func, 'arguments' => $arguments] = json_decode($body, true);
0 ignored issues
show
Bug introduced by
The variable $host does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $func does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $arguments does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
60
61
                Context::push(new Context(getHost($host), $this->input, $this->output));
62
                $answer = call_user_func($func, ...$arguments);
63
                Context::pop();
64
65
                return new Response(200, ['Content-Type' => 'application/json'], json_encode($answer));
66
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
67
68
            default:
69
                throw new Exception('Server path not found: ' . $request->getUri()->getPath());
70
        }
71
    }
72
73 1
    public function addPeriodicTimer($interval, $callback)
74
    {
75 1
        $this->loop->addPeriodicTimer($interval, $callback);
76 1
    }
77
78 1
    public function run()
79
    {
80 1
        $this->loop->run();
81 1
    }
82
83 1
    public function stop()
84
    {
85 1
        $this->loop->stop();
86 1
    }
87
88 1
    public function getPort(): int
89
    {
90 1
        return $this->port;
91
    }
92
}
93