Test Failed
Push — master ( d27da4...a694ed )
by Mehmet
02:06
created

RouterFactory::getRouter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SelamiApp\Factories;
5
6
use Zend\ServiceManager\Factory\FactoryInterface;
7
use Interop\Container\ContainerInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Selami\Router;
10
11
class RouterFactory implements FactoryInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $routes;
17
    /**
18
     * @var Router
19
     */
20
    private $router;
21
    
22
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
23
    {
24
        /**
25
         * @var array $config
26
         */
27
        $config = $container->get('config');
28
        $this->routes = $container->get('routes');
0 ignored issues
show
Documentation Bug introduced by
It seems like $container->get('routes') of type * is incompatible with the declared type array of property $routes.

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...
29
        $request = $container->get(ServerRequestInterface::class);
30
        $this->router = new Router(
31
            $config['app']['default_return_type'] ?? Router::HTML,
32
            $request->getMethod(),
33
            $request->getUri()->getPath(),
34
            '',
35
            $config['app']['cache_file']
36
        );
37
        return $this->getRouter();
38
    }
39
40
    private function getRouter()
41
    {
42
        $this->addRoutes();
43
        return $this->router;
44
    }
45
46
    private function addRoutes()
47
    {
48
        foreach ($this->routes as $route) {
49
            $this->router->add($route[0], $route[1], $route[2], $route[3], $route[4] ?? '');
50
        }
51
    }
52
}