Completed
Push — 1.x ( 1e501f...1f760c )
by Akihito
01:36
created

FakeRun::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use BEAR\AppMeta\AbstractAppMeta;
8
use BEAR\Package\Provide\Error\NullPage;
9
use BEAR\QueryRepository\EtagSetter;
10
use BEAR\QueryRepository\HttpCache;
11
use BEAR\Resource\TransferInterface;
12
use BEAR\Resource\Uri;
13
use BEAR\Sunday\Extension\Application\AppInterface;
14
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
15
use BEAR\Sunday\Provide\Transfer\HttpResponder;
16
use Ray\Aop\ReflectiveMethodInvocation;
17
use Ray\Di\InjectorInterface;
18
19
use function assert;
20
use function class_exists;
21
use function is_callable;
22
use function is_object;
23
use function property_exists;
24
25
class FakeRun
26
{
27
    /** @var InjectorInterface */
28
    private $injector;
29
30
    /** @var string */
31
    private $context;
32
33
    /** @var AbstractAppMeta  */
34
    private $appMeta;
35
36
    public function __construct(InjectorInterface $injector, string $context, AbstractAppMeta $appMeta)
37
    {
38
        $this->injector = $injector;
39
        $this->context = $context;
40
        $this->appMeta = $appMeta;
41
    }
42
43
    /**
44
     * @psalm-suppress MixedFunctionCall
45
     * @psalm-suppress NoInterfaceProperties
46
     * @psalm-suppress MixedMethodCall
47
     * @psalm-suppress MixedPropertyFetch
48
     */
49
    public function __invoke(): void
50
    {
51
        $appBootstrap = $this->appMeta->name . '\Bootstrap';
0 ignored issues
show
Unused Code introduced by
$appBootstrap 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...
52
        $bootstrap = new Bootstrap($this->appMeta);
53
        $_SERVER['HTTP_IF_NONE_MATCH'] = '0';
54
        $_SERVER['REQUEST_URI'] = '/';
55
        $_SERVER['REQUEST_METHOD'] = 'GET';
56
        assert(is_callable($bootstrap));
57
        /** @psalm-suppress PossiblyUndefinedVariable */
58
        ($bootstrap)($this->appMeta->name, $this->context, $GLOBALS, $_SERVER); // 200 OK
59
        $_SERVER['REQUEST_METHOD'] = 'DELETE';
60
        $app = $this->injector->getInstance(AppInterface::class);
61
        assert(is_object($app));
62
        assert(property_exists($app, 'resource'));
63
        assert(property_exists($app, 'responder'));
64
        $ro = $this->injector->getInstance(NullPage::class);
65
        assert($ro instanceof NullPage);
66
        $ro->uri = new Uri('app://self/');
67
        /** @var NullPage $ro */
68
        $ro = $app->resource->get->object($ro)(['required' => 'string']);
69
        assert($app->responder instanceof TransferInterface);
70
        $ro->transfer($app->responder, []);
71
        class_exists(HttpCacheInterface::class);
72
        class_exists(HttpCache::class);
73
        class_exists(HttpResponder::class);
74
        class_exists(EtagSetter::class);
75
        class_exists(ReflectiveMethodInvocation::class);
76
    }
77
}
78