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

RouterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 10 2
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
}