Passed
Branch phpunit-cc-bug (174b22)
by Ekin
05:49
created

server.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php declare(strict_types = 1);
2
3
use Aerys\Host;
4
use Amp\Redis\Client;
5
use Auryn\Injector;
6
use ekinhbayar\GitAmp\Github\Credentials;
7
use ekinhbayar\GitAmp\Storage\Counter;
8
use ekinhbayar\GitAmp\Storage\RedisCounter;
9
use ekinhbayar\GitAmp\Websocket\Handler;
10
use function Aerys\root;
11
use function Aerys\router;
12
use function Aerys\websocket;
13
14
$configuration = require_once __DIR__ . '/config.php';
15
16
$injector = new Injector;
17
18
$injector->alias(Counter::class, RedisCounter::class);
19
20
$injector->alias(Credentials::class, get_class($configuration['github']));
21
22
$injector->share($configuration['github']);
23
24
// @todo unuglify this
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
25
if (isset($configuration['ssl'])) {
26
    $origin = 'https://' . $configuration['hostname'];
27
28
    if ($configuration['ssl']['port'] !== 443) {
29
        $origin .= ':' . $configuration['ssl']['port'];
30
    }
31
} else {
32
    $origin = 'http://' . $configuration['hostname'];
33
34
    if ($configuration['expose']['port'] !== 80) {
35
        $origin .= ':' . $configuration['expose']['port'];
36
    }
37
}
38
39
$injector->define(Handler::class, [
40
    ':origin' => $origin,
41
]);
42
43
$injector->define(Client::class, [
44
    ':uri' => $configuration['redis']
45
]);
46
47
$websocket = $injector->make(Handler::class);
48
49
$router = router()->get("/ws", websocket($websocket));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /ws does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
50
51
if (isset($configuration['ssl'])) {
52
    (new Host())
53
        ->name($configuration['hostname'])
54
        ->expose($configuration['expose']['ip'], $configuration['expose']['port'])
55
        ->redirect('https://' . $configuration['hostname'])
56
    ;
57
58
    (new Host())
59
        ->name($configuration['hostname'])
60
        ->expose($configuration['ssl']['ip'], $configuration['ssl']['port'])
61
        ->encrypt($configuration['ssl']['certificate'], $configuration['ssl']['key'])
62
        ->use($router)
63
        ->use(root(__DIR__ . '/public'))
0 ignored issues
show
\Aerys\root(__DIR__ . '/public') is of type object<Aerys\Bootable>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
    ;
65
} else {
66
    (new Host())
67
        ->name($configuration['hostname'])
68
        ->expose($configuration['expose']['ip'], $configuration['expose']['port'])
69
        ->use($router)
70
        ->use(root(__DIR__ . '/public'))
0 ignored issues
show
\Aerys\root(__DIR__ . '/public') is of type object<Aerys\Bootable>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
    ;
72
}
73