Completed
Push — master ( 47edec...0daa18 )
by Alexander
22:30 queued 07:23
created

RouterFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
namespace Yiisoft\Router;
3
4
class RouterFactory
5
{
6
    private $engineFactory;
7
    private $routes;
8
9
    public function __construct(callable $engineFactory, $routes = [])
10
    {
11
        $this->engineFactory = $engineFactory;
12
        $this->routes = $routes;
13
    }
14
15
    public function __invoke(): RouterInterface
16
    {
17
        $factory = $this->engineFactory;
18
        /* @var $router RouterInterface */
19
        $router = $factory();
20
        foreach ($this->routes as $route) {
21
            $router->addRoute($route);
22
        }
23
        return $router;
24
    }
25
}