VaultBootloader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A makeVault() 0 4 1
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\Container\SingletonInterface;
13
use Spiral\Core\HMVC\CoreInterface;
14
use Spiral\Http\HttpDispatcher;
15
use Spiral\Vault\Configs\VaultConfig;
16
use Spiral\Vault\Vault;
17
18
/**
19
 * Boots vault administration panel bindings and routes. You can always extend this bootloader and
20
 * disable booting to register route manually.
21
 */
22
class VaultBootloader extends Bootloader implements SingletonInterface
23
{
24
    const BOOT = true;
25
26
    /**
27
     * @var \Spiral\Vault\VaultRoute
28
     */
29
    private $route;
30
31
    /**
32
     * @var array
33
     */
34
    const BINDINGS = [
35
        'vault' => Vault::class,
36
    ];
37
38
    /**
39
     * @var array
40
     */
41
    const SINGLETONS = [
42
        Vault::class => [self::class, 'makeVault']
43
    ];
44
45
    /**
46
     * @param HttpDispatcher $http
47
     * @param VaultConfig    $config
48
     */
49
    public function boot(HttpDispatcher $http, VaultConfig $config)
50
    {
51
        $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...
52
53
        $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...
54
    }
55
56
    /**
57
     * @param VaultConfig   $config
58
     * @param CoreInterface $core
59
     *
60
     * @return Vault
61
     */
62
    protected function makeVault(VaultConfig $config, CoreInterface $core): Vault
63
    {
64
        return new Vault($config, $this->route, $core);
65
    }
66
}