Passed
Push — main ( 5b3d5b...c3557b )
by
unknown
54s queued 12s
created

Router   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 28
rs 10
ccs 12
cts 12
cp 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 2
A findRoute() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router;
6
7
use Gacela\Router\Entities\Route;
8
9
final class Router
10
{
11
    /**
12
     * @param callable(Routes, MappingInterfaces):void $fn
13
     */
14 73
    public static function configure(callable $fn): void
15
    {
16 73
        $routerConfigurator = new Routes();
17 73
        $mappingInterfaces = new MappingInterfaces();
18
19 73
        $fn($routerConfigurator, $mappingInterfaces);
20
21 72
        $route = self::findRoute($routerConfigurator);
22
23 72
        if ($route) {
24 65
            echo $route->run($mappingInterfaces);
25
        }
26
    }
27
28 72
    private static function findRoute(Routes $routerConfigurator): ?Route
29
    {
30 72
        foreach ($routerConfigurator->routes() as $route) {
31 72
            if ($route->requestMatches()) {
32 65
                return $route;
33
            }
34
        }
35
36 7
        return null;
37
    }
38
}
39