Completed
Branch develop (fb64bf)
by Anton
02:48
created

VaultBootloader::makeVault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Vault\Bootloaders;
10
11
use Spiral\Core\Bootloaders\Bootloader;
12
use Spiral\Core\ContainerInterface;
13
use Spiral\Http\HttpDispatcher;
14
use Spiral\Vault\Configs\VaultConfig;
15
use Spiral\Vault\Vault;
16
17
/**
18
 * Boots vault administration panel bindings and routes. You can always extend this bootloader and
19
 * disable booting to register route manually.
20
 */
21
class VaultBootloader extends Bootloader
22
{
23
    const BOOT = true;
24
25
    /**
26
     * @var \Spiral\Vault\VaultRoute
27
     */
28
    private $route;
29
30
    /**
31
     * @var array
32
     */
33
    const SINGLETONS = [
34
        'vault' => [self::class, 'makeVault']
35
    ];
36
37
    /**
38
     * @param HttpDispatcher $http
39
     * @param VaultConfig    $config
40
     */
41
    public function boot(HttpDispatcher $http, VaultConfig $config)
42
    {
43
        $this->route = $config->makeRoute('vault')->withCore('vault');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->makeRoute('vault')->withCore('vault') of type object<Spiral\Http\Routing\Traits\CoreTrait> or object<Spiral\Http\Routing\RouteInterface> is incompatible with the declared type object<Spiral\Vault\VaultRoute> of property $route.

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...
44
45
        $http->addRoute($this->route);
0 ignored issues
show
Bug introduced by
It seems like $this->route can also be of type object<Spiral\Http\Routing\Traits\CoreTrait>; however, Spiral\Http\Traits\RouterTrait::addRoute() does only seem to accept object<Spiral\Http\Routing\RouteInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
46
    }
47
48
    /**
49
     * @param VaultConfig        $config
50
     * @param ContainerInterface $container
51
     *
52
     * @return Vault
53
     */
54
    protected function makeVault(VaultConfig $config, ContainerInterface $container): Vault
55
    {
56
        return new Vault($config, $this->route, $container);
0 ignored issues
show
Documentation introduced by
$container is of type object<Spiral\Core\ContainerInterface>, but the function expects a object<Spiral\Core\HMVC\CoreInterface>.

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...
57
    }
58
}