RareloopRouter::testStatic()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
rs 10
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 App\BenchMark\AbstractRouter;
21
use Laminas\Diactoros\ServerRequest;
22
use Rareloop\Router\Router;
23
24
class RareloopRouter extends AbstractRouter
25
{
26
    protected Router $router;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function testStatic(): bool
32
    {
33
        $methods = $this->generator->getMethods();
34
35
        foreach ($methods as $method) {
36
            $path = ($this->strategy)($method);
37
38
            try {
39
                $this->router->match(new ServerRequest([], [], $path, $method));
40
            } catch (\Exception $e) {
41
                return false;
42
            }
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function testPath(): bool
52
    {
53
        $methods = $this->generator->getMethods();
54
55
        foreach ($methods as $method) {
56
            $path = ($this->strategy)($method);
57
58
            try {
59
                $this->router->match(new ServerRequest([], [], $path . 'rareloop_router', $method));
60
            } catch (\Exception $e) {
61
                return false;
62
            }
63
        }
64
65
        return true;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function buildRoutes(array $routes): void
72
    {
73
        $router = new Router();
74
75
        foreach ($routes as $route) {
76
            $router->map($route['methods'], $route['pattern'], fn () => 'Hello')
77
                ->where($route['constraints']);
78
        }
79
80
        $this->router = $router;
81
    }
82
}
83