Bootstrap::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 19
rs 9.8666
cc 2
nc 3
nop 4
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\Router\RouterInterface;
11
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
12
use BEAR\Sunday\Extension\Transfer\TransferInterface;
13
use Throwable;
14
15
use function assert;
16
17
/**
18
 * @psalm-import-type Globals from RouterInterface
19
 * @psalm-import-type Server from RouterInterface
20
 */
21
22
final class Bootstrap
23
{
24
    private string $appDir;
25
26
    public function __construct(AbstractAppMeta $meta)
27
    {
28
        $this->appDir = $meta->appDir;
29
    }
30
31
    /**
32
     * @param Globals $globals
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Compiler\Globals 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...
33
     * @param Server  $server
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Compiler\Server 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...
34
     *
35
     * @return 0|1
0 ignored issues
show
Documentation Bug introduced by
The doc comment 0|1 at position 0 could not be parsed: Unknown type name '0' at position 0 in 0|1.
Loading history...
36
     */
37
    public function __invoke(string $appName, string $context, array $globals, array $server): int
38
    {
39
        $injector =  Injector::getInstance($appName, $context, $this->appDir);
40
        $injector->getInstance(HttpCacheInterface::class);
41
        $router = $injector->getInstance(RouterInterface::class);
42
        assert($router instanceof RouterInterface);
43
        $request = $router->match($globals, $server);
44
        try {
45
            /** @psalm-suppress all */
46
            $resource = $injector->getInstance(ResourceInterface::class);
47
            $resource->{$request->method}->uri($request->path)($request->query);
48
        } catch (Throwable) {
49
            $injector->getInstance(TransferInterface::class);
50
51
            return 1;
52
        }
53
54
        // @codeCoverageIgnoreStart
55
        return 0;
56
        // @codeCoverageIgnoreEnd
57
    }
58
}
59