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
Push — master ( e2875b...35ced9 )
by Anton
03:41
created

Server::addTimer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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
    /**
24
     * @var React\EventLoop\LoopInterface
25
     */
26
    private $loop;
27
    private $port;
28
29 12
    public function __construct(
30
        InputInterface $input,
31
        OutputInterface $output,
32
        QuestionHelper $questionHelper
33
    )
34
    {
35 12
        $this->input = $input;
36 12
        $this->output = $output;
37 12
        $this->questionHelper = $questionHelper;
38 12
    }
39
40 12
    public function start()
41
    {
42 12
        $this->loop = React\EventLoop\Factory::create();
43
        $server = new React\Http\Server($this->loop, function (ServerRequestInterface $request) {
44
            try {
45 4
                return $this->router($request);
46
            } catch (Throwable $exception) {
47
                Deployer::printException($this->output, $exception);
48
                return new React\Http\Message\Response(500, ['Content-Type' => 'text/plain'], 'Master error: ' . $exception->getMessage());
49
            }
50 12
        });
51 12
        $socket = new React\Socket\Server(0, $this->loop);
52 12
        $server->listen($socket);
53 12
        $address = $socket->getAddress();
54 12
        $this->port = parse_url($address, PHP_URL_PORT);
55 12
    }
56
57 4
    private function router(ServerRequestInterface $request): Response
58
    {
59 4
        $path = $request->getUri()->getPath();
60 4
        switch ($path) {
61 4
            case '/load':
62 4
                ['host' => $host] = json_decode($request->getBody(), true);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
63
64 4
                $host = getHost($host);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
65 4
                $config = json_encode($host->config()->persist());
66
67 4
                return new Response(200, ['Content-Type' => 'application/json'], $config);
68
69 4
            case '/save':
70 4
                ['host' => $host, 'config' => $config] = json_decode($request->getBody(), true);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
Bug introduced by Anton Medvedev
The variable $config seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
71
72 4
                $host = getHost($host);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
73 4
                $host->config()->update($config);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $config seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
74
75 4
                return new Response(200, ['Content-Type' => 'application/json'], 'true');
76
77 1
            case '/proxy':
78 1
                ['host' => $host, 'func' => $func, 'arguments' => $arguments] = json_decode($request->getBody(), true);
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
Bug introduced by Anton Medvedev
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 Anton Medvedev
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...
79
80 1
                Context::push(new Context(getHost($host), $this->input, $this->output));
0 ignored issues
show
Bug introduced by Anton Medvedev
The variable $host seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
81 1
                $answer = call_user_func($func, ...$arguments);
82 1
                Context::pop();
83
84 1
                return new Response(200, ['Content-Type' => 'application/json'], json_encode($answer));
85
86
            default:
87
                throw new Exception('Server path not found: ' . $request->getUri()->getPath());
88
        }
89
    }
90
91 4
    public function addPeriodicTimer($interval, $callback)
92
    {
93 4
        $this->loop->addPeriodicTimer($interval, $callback);
94 4
    }
95
96 4
    public function addTimer($interval, $callback)
97
    {
98 4
        $this->loop->addTimer($interval, $callback);
99 4
    }
100
101 4
    public function cancelTimer($timer)
102
    {
103 4
        $this->loop->cancelTimer($timer);
104 4
    }
105
106 4
    public function run()
107
    {
108 4
        $this->loop->run();
109 4
    }
110
111 4
    public function stop()
112
    {
113 4
        $this->loop->stop();
114 4
    }
115
116 4
    public function getPort(): int
117
    {
118 4
        return $this->port;
119
    }
120
}
121