Completed
Pull Request — 1.x (#357)
by Akihito
03:11 queued 01:34
created

Bootstrap::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use BEAR\Package\Injector;
8
use BEAR\Sunday\Extension\Application\AppInterface;
9
use Throwable;
10
11
use function dirname;
12
13
/**
14
 * @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface
15
 * @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface
16
 */
17
final class Bootstrap
18
{
19
    /**
20
     * @psalm-param Globals $globals
21
     * @psalm-param Server  $server
22
     * @phpstan-param array<string, mixed> $globals
23
     * @phpstan-param array<string, mixed> $server
24
     *
25
     * @return 0|1
0 ignored issues
show
Documentation introduced by
The doc-type 0|1 could not be parsed: Unknown type name "0" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
26
     */
27
    public function __invoke(string $appName, string $context, array $globals, array $server): int
28
    {
29
        $tmpDir = dirname(__DIR__, 2) . '/tests/tmp';
30
        $app = Injector::getInstance($appName, $context, $tmpDir)->getInstance(AppInterface::class);
31
        $app->httpCache->isNotModified($server);
32
33
        $request = $app->router->match($globals, $server);
34
        try {
35
            /** @psalm-suppress all */
36
            $app->resource->{$request->method}->uri($request->path)($request->query);
37
        } catch (Throwable $e) {
38
            $app->throwableHandler->handle($e, $request)->transfer();
39
40
            return 1;
41
        }
42
43
        // @codeCoverageIgnoreStart
44
        return 0;
45
    }
46
}
47