Completed
Branch 2.0 (13ec26)
by Anton
05:17
created

HttpBootloader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A core() 0 11 1
A router() 0 6 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Http\Bootloaders;
10
11
use Psr\Container\ContainerInterface;
12
use Psr\Http\Message\ResponseFactoryInterface;
13
use Spiral\Boot\KernelInterface;
14
use Spiral\Core\Bootloaders\Bootloader;
15
use Spiral\Core\Core;
16
use Spiral\Core\CoreInterface;
17
use Spiral\Http\Configs\HttpConfig;
18
use Spiral\Http\HttpCore;
19
use Spiral\Http\HttpDispatcher;
20
use Spiral\Http\Pipeline;
21
use Spiral\Router\Router;
22
use Spiral\Router\RouterInterface;
23
use Zend\HttpHandlerRunner\Emitter\EmitterInterface;
24
use Zend\HttpHandlerRunner\Emitter\SapiEmitter;
25
26
class HttpBootloader extends Bootloader
27
{
28
    const BOOT = true;
29
30
    const SINGLETONS = [
31
        EmitterInterface::class         => SapiEmitter::class,
32
        ResponseFactoryInterface::class => HttpCore::class,
33
        CoreInterface::class            => Core::class,
34
        HttpCore::class                 => [self::class, 'core'],
35
        RouterInterface::class          => [self::class, 'router']
36
    ];
37
38
    /**
39
     * @param KernelInterface $kernel
40
     * @param HttpDispatcher  $http
41
     */
42
    public function boot(KernelInterface $kernel, HttpDispatcher $http)
43
    {
44
        $kernel->addDispatcher($http);
45
    }
46
47
    /**
48
     * @param HttpConfig         $config
49
     * @param ContainerInterface $container
50
     * @param RouterInterface    $router
51
     * @param Pipeline           $pipeline
52
     * @return HttpCore
53
     */
54
    protected function core(
55
        HttpConfig $config,
56
        ContainerInterface $container,
57
        RouterInterface $router,
58
        Pipeline $pipeline
59
    ): HttpCore {
60
        $core = new HttpCore($config, $pipeline, $container);
61
        $core->setHandler($router);
0 ignored issues
show
Documentation introduced by
$router is of type object<Spiral\Router\RouterInterface>, but the function expects a callable.

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...
62
63
        return $core;
64
    }
65
66
    /**
67
     * @param HttpConfig         $config
68
     * @param ContainerInterface $container
69
     * @return RouterInterface
70
     */
71
    protected function router(
72
        HttpConfig $config,
73
        ContainerInterface $container
74
    ): RouterInterface {
75
        return new Router($config->basePath(), $container);
76
    }
77
}