Passed
Pull Request — master (#88)
by Rustam
07:19
created

RouterCollector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10
c 3
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexData() 0 4 1
A collect() 0 3 1
A getCollected() 0 11 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Router\RouteCollectionInterface;
9
10
final class RouterCollector implements RouterCollectorInterface, IndexCollectorInterface
11
{
12
    use CollectorTrait;
13
14
    private ContainerInterface $container;
15
    private float $matchTime = 0;
16
17 1
    public function __construct(ContainerInterface $container)
18
    {
19 1
        $this->container = $container;
20 1
    }
21
22 1
    public function collect(float $matchTime): void
23
    {
24 1
        $this->matchTime = $matchTime;
25 1
    }
26
27 1
    public function getCollected(): array
28
    {
29 1
        $routeCollection = $this->container->has(RouteCollectionInterface::class)
30 1
            ? $this->container->get(RouteCollectionInterface::class)
31 1
            : null;
32
33 1
        return $routeCollection === null ? [] :
34
            [
35 1
                'routesTree' => $routeCollection->getRouteTree(),
36 1
                'routes' => $routeCollection->getRoutes(),
37 1
                'routeTime' => $this->matchTime,
38
            ];
39
    }
40
41 1
    public function getIndexData(): array
42
    {
43
        return [
44 1
            'routeMatchTime' => $this->matchTime,
45
        ];
46
    }
47
}
48