Completed
Pull Request — 1.x (#10)
by
unknown
12:26
created

Boot::getContxtualModule()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 2
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 4
rs 9.7
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the BEAR.Middleware package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Middleware;
8
9
use BEAR\AppMeta\AbstractAppMeta;
10
use BEAR\Middleware\Module\AppMetaModule;
11
use BEAR\Middleware\Module\MiddlewareModule;
12
use BEAR\Middleware\Module\StreamModule;
13
use BEAR\Package\Module;
14
use Ray\Compiler\DiCompiler;
15
use Ray\Compiler\Exception\NotCompiled;
16
use Ray\Compiler\ScriptInjector;
17
use Ray\Di\InjectorInterface;
18
19
class Boot
20
{
21 3
    public function getInjector(AbstractAppMeta $appMeta, $contexts)
22
    {
23
        try {
24 3
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
25 3
        } catch (NotCompiled $e) {
26 3
            $module = (new Module)($appMeta, $contexts);
27 2
            $module->override(new MiddlewareModule(new AppMetaModule($appMeta)));
0 ignored issues
show
Documentation introduced by
new \BEAR\Middleware\Mod...AppMetaModule($appMeta) is of type object<BEAR\Middleware\Module\AppMetaModule>, but the function expects a null|object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28 2
            $compiler = new DiCompiler(new StreamModule($module), $appMeta->tmpDir);
29 2
            $compiler->compile();
30 2
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
31
        }
32
33 2
        return $injector;
34
    }
35
}
36