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

DriftKernelAdapter::shutDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\React;
6
7
use Antidot\Application\Http\Application;
8
use Drift\Console\OutputPrinter;
9
use Drift\Server\Adapter\KernelAdapter;
10
use Drift\Server\Context\ServerContext;
11
use Drift\Server\Mime\MimeTypeChecker;
12
use Psr\Container\ContainerInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
use React\EventLoop\LoopInterface;
15
use React\Filesystem\FilesystemInterface;
0 ignored issues
show
Bug introduced by
The type React\Filesystem\FilesystemInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use React\Promise\PromiseInterface;
17
use function React\Promise\resolve;
18
19
final class DriftKernelAdapter implements KernelAdapter
20
{
21
    private ServerContext $serverContext;
22
    private MimeTypeChecker $mimeTypeChecker;
23
    private string $rootPath;
24
    private ContainerInterface $container;
25
    private ReactApplication $application;
26
    /** @var object|FilesystemInterface|null  */
27
    private ?object $filesystem = null;
28
29
    public function __construct(
30
        ServerContext $serverContext,
31
        MimeTypeChecker $mimeTypeChecker,
32
        string $rootPath,
33
        ?object $filesystem
34
    ) {
35
        $container = require $rootPath . '/config/container.php';
36
        assert($container instanceof ContainerInterface);
37
        $application = $container->get(Application::class);
38
        assert($application instanceof ReactApplication);
39
        (require $rootPath . '/router/middleware.php')($application, $container);
40
        (require $rootPath . '/router/routes.php')($application, $container);
41
        $this->container = $container;
42
        $this->application = $application;
43
        $this->serverContext = $serverContext;
44
        $this->filesystem = $filesystem;
45
        $this->mimeTypeChecker = $mimeTypeChecker;
46
        $this->rootPath = $rootPath;
47
    }
48
49
    /** @psalm-suppress MixedReturnTypeCoercion */
50
    public static function create(
51
        LoopInterface $loop,
52
        string $rootPath,
53
        ServerContext $serverContext,
54
        OutputPrinter $outputPrinter,
55
        MimeTypeChecker $mimeTypeChecker,
56
        $filesystem = null
57
    ): PromiseInterface {
58
        return resolve(new self($serverContext, $mimeTypeChecker, $rootPath, $filesystem))
59
            ->then(fn (KernelAdapter $adapter): KernelAdapter => $adapter);
60
    }
61
62
    /**
63
     * @psalm-suppress LessSpecificImplementedReturnType
64
     * @param ServerRequestInterface $request
65
     * @return PromiseResponse
66
     */
67
    public function handle(ServerRequestInterface $request): PromiseResponse
68
    {
69
        return $this->application->handle($request);
70
    }
71
72
    public static function getStaticFolder(): ?string
73
    {
74
        return 'public';
75
    }
76
77
    public function shutDown(): PromiseInterface
78
    {
79
        return resolve('nothing to do');
80
    }
81
82
    /**
83
     * Get watcher folders.
84
     *
85
     * @return string[]
86
     */
87
    public static function getObservableFolders(): array
88
    {
89
        return ['src', 'public', 'templates'];
90
    }
91
92
    /**
93
     * Get watcher folders.
94
     *
95
     * @return string[]
96
     */
97
    public static function getObservableExtensions(): array
98
    {
99
        return ['php', 'yml', 'yaml', 'xml', 'css', 'js', 'html', 'twig'];
100
    }
101
102
    /**
103
     * Get watcher ignoring folders.
104
     *
105
     * @return string[]
106
     */
107
    public static function getIgnorableFolders(): array
108
    {
109
        return ['var'];
110
    }
111
}
112