Passed
Pull Request — main (#7)
by
unknown
02:19
created

Router::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
ccs 7
cts 7
cp 1
crap 2
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