Passed
Push — drift_server ( 5c2da8...258843 )
by Koldo
12:53
created

ConfigProvider::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 19
ccs 3
cts 3
cp 1
rs 9.7666
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Antidot\React\Container\Config;
4
5
use Antidot\Application\Http\Application;
6
use Antidot\React\LoopFactory;
7
use Antidot\React\ReactApplicationFactory;
8
use Antidot\React\RunServerCommandFactory;
9
use Antidot\React\ServerFactory;
10
use Antidot\React\SocketFactory;
11
use Antidot\React\WatchServerCommandFactory;
12
use Drift\Server\Console\RunServerCommand;
13
use Drift\Server\Console\WatchServerCommand;
14
use React\EventLoop\LoopInterface;
15
use React\Http\Server;
16
use React\Socket\Server as Socket;
17
18
class ConfigProvider
19
{
20
    private const DEFAULT_HOST = '0.0.0.0';
21
    private const DEFAULT_PORT = 8080;
22
    private const DEFAULT_CONCURRENCY = 100;
23
    private const DEFAULT_BUFFER_SIZE = 4 * 1024 * 1024;
24
25 1
    public function __invoke(): array
26
    {
27
        return [
28
            'dependencies' => [
29
                'factories' => [
30 1
                    Application::class => ReactApplicationFactory::class,
31
                    LoopInterface::class => LoopFactory::class,
32
                    Server::class => ServerFactory::class,
33
                    Socket::class => SocketFactory::class,
34
                ],
35
            ],
36 1
            'console' => $this->getConsoleConfig(),
37
            'server' => [
38
                'host' => '0.0.0.0',
39
                'port' => 5555,
40
                'buffer_size' => 4096,
41
                'max_concurrency' => 100,
42
                'workers' => 1,
43
                'static_folder' => 'public'
44
            ]
45
        ];
46
    }
47
48 1
    private function getConsoleConfig(): array
49
    {
50 1
        $hasWatcher = class_exists(WatchServerCommand::class);
51
52 1
        return $hasWatcher
53
            ? [
54
                'commands' => [
55 1
                    'server:run' => RunServerCommand::class,
56
                    'server:watch' => WatchServerCommand::class
57
                ],
58
                'factories' => [
59
                    RunServerCommand::class => RunServerCommandFactory::class,
60
                    WatchServerCommand::class => WatchServerCommandFactory::class,
61
                ]
62
            ]
63
            : [
64
                'commands' => [
65 1
                    'server:run' => RunServerCommand::class,
66
                ],
67
                'factories' => [
68
                    RunServerCommand::class => RunServerCommandFactory::class,
69
                ]
70
            ];
71
    }
72
}
73