AltRouter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testPath() 0 13 3
A buildRoutes() 0 11 3
A testStatic() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace App\BenchMark\Routers;
19
20
use AltoRouter;
21
use App\BenchMark\AbstractRouter;
22
23
class AltRouter extends AbstractRouter
24
{
25
    public const PATH = '[a:action]';
26
27
    protected AltoRouter $router;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function testStatic(): bool
33
    {
34
        $methods = $this->generator->getMethods();
35
36
        foreach ($methods as $method) {
37
            $path = ($this->strategy)($method);
38
39
            if (!$this->router->match($path, $method)) {
40
                return false;
41
            }
42
        }
43
44
        return true;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function testPath(): bool
51
    {
52
        $methods = $this->generator->getMethods();
53
54
        foreach ($methods as $method) {
55
            $path = ($this->strategy)($method);
56
57
            if (!$this->router->match($path . 'altorouter', $method)) {
58
                return false;
59
            }
60
        }
61
62
        return true;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function buildRoutes(array $routes): void
69
    {
70
        $router = new AltoRouter();
71
72
        foreach ($routes as $route) {
73
            foreach ($route['methods'] as $method) {
74
                $router->map($method, $route['pattern'], fn () => 'Hello');
75
            }
76
        }
77
78
        $this->router = $router;
79
    }
80
}
81