Completed
Push — compiler ( 5bd2e3...2cb518 )
by Akihito
09:43
created

Bootstrap::__invoke()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 3
nc 5
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use BEAR\Package\Injector;
8
use BEAR\Resource\ResourceObject;
9
use BEAR\Sunday\Extension\Application\AppInterface;
10
use Throwable;
11
12
use function assert;
13
use function dirname;
14
15
/**
16
 * @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface
17
 * @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface
18
 */
19
final class Bootstrap
20
{
21
    /**
22
     * @psalm-param Globals $globals
23
     * @psalm-param Server  $server
24
     * @phpstan-param array<string, mixed> $globals
25
     * @phpstan-param array<string, mixed> $server
26
     *
27
     * @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...
28
     */
29
    public function __invoke(string $context, array $globals, array $server): int
30
    {
31
        $tmpDir = dirname(__DIR__, 2) . '/tests/tmp';
32
        $app = Injector::getInstance('BEAR\Package\Compiler', $context, $tmpDir)->getInstance(AppInterface::class);
33
        assert($app instanceof AppInterface);
34
        if ($app->httpCache->isNotModified($server)) {
0 ignored issues
show
Bug introduced by
Accessing httpCache on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
35
            $app->httpCache->transfer();
0 ignored issues
show
Bug introduced by
Accessing httpCache on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
36
37
            return 0;
38
        }
39
40
        $request = $app->router->match($globals, $server);
0 ignored issues
show
Bug introduced by
Accessing router on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
41
        try {
42
            $response = $app->resource->{$request->method}->uri($request->path)($request->query);
0 ignored issues
show
Bug introduced by
Accessing resource on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
43
            assert($response instanceof ResourceObject);
44
            $response->transfer($app->responder, $server);
0 ignored issues
show
Bug introduced by
Accessing responder on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
45
46
            return 0;
47
        } catch (Throwable $e) {
48
            $app->throwableHandler->handle($e, $request)->transfer();
0 ignored issues
show
Bug introduced by
Accessing throwableHandler on the interface BEAR\Sunday\Extension\Application\AppInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
49
50
            return 1;
51
        }
52
    }
53
}
54