Passed
Pull Request — 2.x.x (#12)
by Koldo
05:21 queued 02:46
created

WatchServerCommandFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 28
ccs 0
cts 21
cp 0
rs 9.6
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\React;
6
7
use Drift\Server\Console\WatchServerCommand;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class WatchServerCommandFactory
12
{
13
    public function __invoke(ContainerInterface $container): WatchServerCommand
14
    {
15
        /** @var array<string, array> $globalConfig */
16
        $globalConfig = $container->get('config');
17
        /** @var array<string, string|int> $config */
18
        $config = $globalConfig['server'];
19
20
        $command = new WatchServerCommand(dirname('./'), [
21
            'bin/console',
22
            'server:run',
23
            sprintf('--adapter=%s', DriftKernelAdapter::class),
24
            '--debug',
25
        ], 'server:watch');
26
        $definition = $command->getDefinition();
27
        $command->setDescription('Watch Drift HTTP Server for development purposes');
28
29
        $path = new InputArgument('path', InputArgument::OPTIONAL, $definition->getArgument('path')->getDescription());
30
        $path->setDefault(sprintf('%s:%s', $config['host'], $config['port']));
31
        $definition->setArguments([$path]);
32
33
        $staticFolder = $definition->getOption('static-folder');
34
        $staticFolder->setDefault($config['static_folder']);
35
        $concurrentRequests = $definition->getOption('concurrent-requests');
36
        $concurrentRequests->setDefault($config['max_concurrency']);
37
        $bufferSize = $definition->getOption('request-body-buffer');
38
        $bufferSize->setDefault($config['buffer_size']);
39
40
        return $command;
41
    }
42
}
43