Passed
Push — master ( 21b640...a85aeb )
by Vladimir
02:52
created

RouteServiceProvider::buildPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
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 1
    public function register(): void
42
    {
43
        $this->container->share('request', function () {
44 1
            return ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
45 1
        });
46 1
        $this->container->share('response', Response::class);
47 1
        $this->container->share('emitter', SapiEmitter::class);
48
49 1
        $this->container->share('router', function () {
50 1
            $router = new RouteCollection($this->container);
51
52 1
            $this->routes($router);
53
54 1
            return $router;
55 1
        });
56 1
    }
57
}
58