Passed
Push — master ( 03e013...bd5966 )
by Anatoly
01:18 queued 14s
created

RouterFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 27
c 1
b 0
f 0
ccs 9
cts 10
cp 0.9
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createRouter() 0 16 2
1
<?php declare(strict_types=1);
2
3
namespace App\Factory;
4
5
/**
6
 * Import classes
7
 */
8
use Psr\Container\ContainerInterface;
9
use Sunrise\Http\Router\Loader\AnnotationDirectoryLoader;
10
use Sunrise\Http\Router\Router;
11
12
/**
13
 * RouterFactory
14
 *
15
 * Don't use this factory outside the container!
16
 */
17
final class RouterFactory
18
{
19
20
    /**
21
     * Creates Router instance
22
     *
23
     * @param array $params
24
     * @param ContainerInterface $container
25
     *
26
     * @return Router
27
     */
28 25
    public function createRouter(array $params, ContainerInterface $container) : Router
29
    {
30 25
        $router = new Router();
31 25
        $router->addMiddleware(...$params['middlewares']);
32
33 25
        $loader = new AnnotationDirectoryLoader();
34 25
        $loader->setContainer($container);
35
36 25
        if (isset($params['metadata']['cache'])) {
37
            $loader->setCache($params['metadata']['cache']);
38
        }
39
40 25
        $loader->attach(...$params['metadata']['sources']);
0 ignored issues
show
Bug introduced by
$params['metadata']['sources'] is expanded, but the parameter $resource of Sunrise\Http\Router\Load...rectoryLoader::attach() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $loader->attach(/** @scrutinizer ignore-type */ ...$params['metadata']['sources']);
Loading history...
41 25
        $router->load($loader);
42
43 25
        return $router;
44
    }
45
}
46