Test Failed
Push — master ( bdaab5...176ee2 )
by Vladimir
06:36
created

RouteServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
routes() 0 1 ?
A register() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use Zend\Diactoros\Response;
8
use League\Route\RouteCollection;
9
use Zend\Diactoros\Response\SapiEmitter;
10
use Zend\Diactoros\ServerRequestFactory;
11
use League\Container\ServiceProvider\AbstractServiceProvider;
12
13
abstract class RouteServiceProvider extends AbstractServiceProvider
14
{
15
    protected $provides = [
16
        'request',
17
        'response',
18
        'emitter',
19
        'router',
20
    ];
21
22
    /**
23
     * Define routes.
24
     *
25
     * @param RouteCollection $routes
26
     *
27
     * @return void
28
     */
29
    abstract public function routes(RouteCollection $routes): void;
30
31
    /**
32
     * Use the register method to register items with the container via the
33
     * protected $this->container property or the `getContainer` method
34
     * from the ContainerAwareTrait.
35
     *
36
     * @return void
37
     * @throws \Psr\Container\NotFoundExceptionInterface
38
     * @throws \Psr\Container\ContainerExceptionInterface
39
     * @throws \InvalidArgumentException
40
     */
41
    public function register(): void
42
    {
43
        $this->container->share('request', ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES));
44
        $this->container->share('response', Response::class);
45
        $this->container->share('emitter', SapiEmitter::class);
46
47
        $this->container->share('router', function () {
48
            $router = new RouteCollection($this->container);
49
50
            $this->routes($router);
51
52
            return $router;
53
        });
54
    }
55
}
56