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

Router::findRoute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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