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 Monolog\Logger; |
||
11 | use Monolog\Handler\StreamHandler; |
||
12 | use Psr\Log\LoggerInterface; |
||
13 | use function Aerys\root; |
||
14 | use function Aerys\router; |
||
15 | use function Aerys\websocket; |
||
16 | |||
17 | //require_once __DIR__ . '/vendor/autoload.php'; |
||
18 | |||
19 | $configuration = require_once __DIR__ . '/config.php'; |
||
20 | |||
21 | $injector = new Injector; |
||
22 | |||
23 | $injector->alias(Counter::class, RedisCounter::class); |
||
24 | |||
25 | $injector->alias(Credentials::class, get_class($configuration['github'])); |
||
26 | |||
27 | $injector->share($configuration['github']); |
||
28 | |||
29 | $injector->alias(LoggerInterface::class, Logger::class); |
||
30 | $injector->share(Logger::class); |
||
31 | |||
32 | $injector->delegate(Logger::class, function() use ($configuration) { |
||
33 | $logger = new Logger('gitamp'); |
||
34 | |||
35 | $logger->pushHandler(new StreamHandler('php://stdout', $configuration['logLevel'])); |
||
36 | |||
37 | return $logger; |
||
38 | }); |
||
39 | |||
40 | // @todo unuglify this |
||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
![]() |
|||
41 | if (isset($configuration['ssl'])) { |
||
42 | $origin = 'https://' . $configuration['hostname']; |
||
43 | |||
44 | View Code Duplication | if ($configuration['ssl']['port'] !== 443) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
45 | $origin .= ':' . $configuration['ssl']['port']; |
||
46 | } |
||
47 | } else { |
||
48 | $origin = 'http://' . $configuration['hostname']; |
||
49 | |||
50 | View Code Duplication | if ($configuration['expose']['port'] !== 80) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
51 | $origin .= ':' . $configuration['expose']['port']; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $injector->define(Handler::class, [ |
||
56 | ':origin' => $origin, |
||
57 | ]); |
||
58 | |||
59 | $injector->define(Client::class, [ |
||
60 | ':uri' => $configuration['redis'] |
||
61 | ]); |
||
62 | |||
63 | $websocket = $injector->make(Handler::class); |
||
64 | |||
65 | $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 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 ( 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: 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. ![]() |
|||
66 | |||
67 | if (isset($configuration['ssl'])) { |
||
68 | (new Host()) |
||
69 | ->name($configuration['hostname']) |
||
70 | ->expose($configuration['expose']['ip'], $configuration['expose']['port']) |
||
71 | ->redirect('https://' . $configuration['hostname']) |
||
72 | ; |
||
73 | |||
74 | (new Host()) |
||
75 | ->name($configuration['hostname']) |
||
76 | ->expose($configuration['ssl']['ip'], $configuration['ssl']['port']) |
||
77 | ->encrypt($configuration['ssl']['certificate'], $configuration['ssl']['key']) |
||
78 | ->use($router) |
||
79 | ->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);
![]() |
|||
80 | ; |
||
81 | } else { |
||
82 | (new Host()) |
||
83 | ->name($configuration['hostname']) |
||
84 | ->expose($configuration['expose']['ip'], $configuration['expose']['port']) |
||
85 | ->use($router) |
||
86 | ->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);
![]() |
|||
87 | ; |
||
88 | } |
||
89 | |||
90 | $logger = $injector->make(LoggerInterface::class); |
||
91 | |||
92 | \Amp\onError(function(Throwable $e) use ($logger) { |
||
93 | $logger->emergency('GitAmp blew up', ['exception' => $e]); |
||
94 | }); |
||
95 |