Passed
Push — master ( cf37f2...bd53e8 )
by Alexander
02:23
created

RouterCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 17
c 3
b 0
f 0
dl 0
loc 38
ccs 16
cts 18
cp 0.8889
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getIndexData() 0 4 1
A collect() 0 6 2
A getCollected() 0 11 3
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
        if (!$this->isActive()) {
25
            return;
26
        }
27 1
        $this->matchTime = $matchTime;
28 1
    }
29
30 1
    public function getCollected(): array
31
    {
32 1
        $routeCollection = $this->container->has(RouteCollectionInterface::class)
33 1
            ? $this->container->get(RouteCollectionInterface::class)
34
            : null;
35
36 1
        return $routeCollection === null ? [] :
37
            [
38 1
                'routesTree' => $routeCollection->getRouteTree(),
39 1
                'routes' => $routeCollection->getRoutes(),
40 1
                'routeTime' => $this->matchTime,
41
            ];
42
    }
43
44 1
    public function getIndexData(): array
45
    {
46
        return [
47 1
            'routeMatchTime' => $this->matchTime,
48
        ];
49
    }
50
}
51