Completed
Push — master ( 0daa18...fc0f8c )
by Alexander
20:49 queued 05:57
created

RouterFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 10 2
A __set_state() 0 4 1
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
26
    public static function __set_state($properties)
27
    {
28
        return new self($properties['engineFactory'], $properties['routes']);
29
    }
30
}
31