Completed
Push — v1 ( 657f5c...f879dd )
by Ekin
07:13 queued 26s
created

server.php (2 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 Auryn\Injector;
5
use ekinhbayar\GitAmp\Github\Credentials;
6
use ekinhbayar\GitAmp\Http\Origin;
7
use ekinhbayar\GitAmp\Log\Request as RequestLogger;
8
use ekinhbayar\GitAmp\Storage\Counter;
9
use ekinhbayar\GitAmp\Storage\NativeCounter;
10
use ekinhbayar\GitAmp\Websocket\Handler;
11
use Monolog\Logger;
12
use Monolog\Handler\StreamHandler;
13
use Psr\Log\LoggerInterface;
14
use function Aerys\root;
15
use function Aerys\router;
16
use function Aerys\websocket;
17
18
$configuration = require_once __DIR__ . '/config.php';
19
20
$injector = new Injector;
21
22
$injector->alias(Counter::class, NativeCounter::class);
23
24
$injector->alias(Credentials::class, get_class($configuration['github']));
25
26
$injector->share($configuration['github']);
27
28
$injector->alias(LoggerInterface::class, Logger::class);
29
$injector->share(Logger::class);
30
31
$injector->delegate(Logger::class, function() use ($configuration) {
32
    $logger = new Logger('gitamp');
33
34
    $logger->pushHandler(new StreamHandler('php://stdout', $configuration['logLevel']));
35
36
    return $logger;
37
});
38
39
$injector->define(Handler::class, [
40
    ':origin' => (new Origin($configuration))->get(),
41
]);
42
43
$websocket = $injector->make(Handler::class);
44
45
$router = router()->get('/ws', websocket($websocket));
46
47
$requestLogger = new RequestLogger();
48
49
if (isset($configuration['ssl'])) {
50
    (new Host())
51
        ->name($configuration['hostname'])
52
        ->expose($configuration['expose']['ip'], $configuration['expose']['port'])
53
        ->use($requestLogger)
54
        ->redirect('https://' . $configuration['hostname'])
55
    ;
56
57
    (new Host())
58
        ->name($configuration['hostname'])
59
        ->expose($configuration['ssl']['ip'], $configuration['ssl']['port'])
60
        ->encrypt($configuration['ssl']['certificate'], $configuration['ssl']['key'])
61
        ->use($requestLogger)
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($requestLogger)
70
        ->use($router)
71
        ->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...
72
    ;
73
}
74
75
$logger = $injector->make(LoggerInterface::class);
76
77
\Amp\onError(function(Throwable $e) use ($logger) {
78
    $logger->emergency('GitAmp blew up', ['exception' => $e]);
79
});
80