Completed
Push — compiler ( d6bb7f...294fd1 )
by Akihito
01:45
created

Bootstrap::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use BEAR\AppMeta\AbstractAppMeta;
8
use BEAR\Package\Injector;
9
use BEAR\Resource\ResourceInterface;
10
use BEAR\Sunday\Extension\Application\AppInterface;
11
use BEAR\Sunday\Extension\Router\RouterInterface;
12
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
13
use BEAR\Sunday\Extension\Transfer\TransferInterface;
14
use Throwable;
15
16
/**
17
 * @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface
18
 * @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface
19
 */
20
21
final class Bootstrap
22
{
23
    /** @var string */
24
    private $appDir;
25
26
    public function __construct(AbstractAppMeta $meta)
27
    {
28
        $this->appDir = $meta->appDir;
29
    }
30
31
    /**
32
     * @psalm-param Globals $globals
33
     * @psalm-param Server  $server
34
     * @phpstan-param array<string, mixed> $globals
35
     * @phpstan-param array<string, mixed> $server
36
     *
37
     * @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...
38
     */
39
    public function __invoke(string $appName, string $context, array $globals, array $server): int
40
    {
41
        $injector =  Injector::getInstance($appName, $context, $this->appDir);
42
        $app = $injector->getInstance(AppInterface::class);
0 ignored issues
show
Unused Code introduced by
$app is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
        $injector->getInstance(HttpCacheInterface::class);
44
        $router = $injector->getInstance(RouterInterface::class);
45
        $request = $router->match($globals, $server);
46
        try {
47
            /** @psalm-suppress all */
48
            $resource = $injector->getInstance(ResourceInterface::class);
49
            $resource->{$request->method}->uri($request->path)($request->query);
50
        } catch (Throwable $e) {
51
            $injector->getInstance(TransferInterface::class);
52
53
            return 1;
54
        }
55
56
        // @codeCoverageIgnoreStart
57
        return 0;
58
    }
59
}
60