Bootstrap   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
dl 0
loc 37
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 20 2
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\Package\Types;
10
use BEAR\Resource\ResourceInterface;
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
use function assert;
17
18
/**
19
 * @psalm-import-type Globals from RouterInterface
20
 * @psalm-import-type Server from RouterInterface
21
 * @psalm-import-type AppName from Types
22
 * @psalm-import-type Context from Types
23
 * @psalm-import-type AppDir from Types
24
 */
25
26
final class Bootstrap
27
{
28
    private string $appDir;
29
30
    public function __construct(AbstractAppMeta $meta)
31
    {
32
        $this->appDir = $meta->appDir;
0 ignored issues
show
Documentation Bug introduced by
It seems like $meta->appDir of type string is incompatible with the declared type BEAR\AppMeta\AppDir of property $appDir.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    /**
36
     * @param AppName $appName
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Compiler\AppName 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...
37
     * @param Context $context
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Compiler\Context 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...
38
     * @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...
39
     * @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...
40
     *
41
     * @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...
42
     */
43
    public function __invoke(string $appName, string $context, array $globals, array $server): int
44
    {
45
        assert($this->appDir !== '');
46
        $injector =  Injector::getInstance($appName, $context, $this->appDir);
47
        $injector->getInstance(HttpCacheInterface::class);
48
        $router = $injector->getInstance(RouterInterface::class);
49
        assert($router instanceof RouterInterface);
50
        $request = $router->match($globals, $server);
51
        try {
52
            /** @psalm-suppress all */
53
            $resource = $injector->getInstance(ResourceInterface::class);
54
            $resource->{$request->method}->uri($request->path)($request->query);
55
        } catch (Throwable) {
56
            $injector->getInstance(TransferInterface::class);
57
58
            return 1;
59
        }
60
61
        // @codeCoverageIgnoreStart
62
        return 0;
63
        // @codeCoverageIgnoreEnd
64
    }
65
}
66