Issues (14)

src/Routers/BramusRouter.php (2 issues)

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 Bramus\Router\Router;
22
23
class BramusRouter extends AbstractRouter
24
{
25
    protected Router $router;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function testStatic(): bool
31
    {
32
        $methods = $this->generator->getMethods();
33
34
        foreach ($methods as $method) {
35
            $path = ($this->strategy)($method);
36
37
            $_SERVER['REQUEST_METHOD'] = $method;
38
            $_SERVER['SCRIPT_NAME'] = '';
39
            $_SERVER['REQUEST_URI'] = $path;
40
41
            if (!$this->router->run($method, $path)) {
0 ignored issues
show
The call to Bramus\Router\Router::run() has too many arguments starting with $path. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            if (!$this->router->/** @scrutinizer ignore-call */ run($method, $path)) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
42
                return false;
43
            }
44
        }
45
46
        return true;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function testPath(): bool
53
    {
54
        $methods = $this->generator->getMethods();
55
56
        foreach ($methods as $method) {
57
            $path = ($this->strategy)($method);
58
59
            $_SERVER['REQUEST_METHOD'] = $method;
60
            $_SERVER['SCRIPT_NAME'] = '';
61
            $_SERVER['REQUEST_URI'] = $path;
62
63
            if (!$this->router->run($method, $path . 'bramus_router')) {
0 ignored issues
show
The call to Bramus\Router\Router::run() has too many arguments starting with $path . 'bramus_router'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
            if (!$this->router->/** @scrutinizer ignore-call */ run($method, $path . 'bramus_router')) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
64
                return false;
65
            }
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function buildRoutes(array $routes): void
75
    {
76
        $router = new Router();
77
78
        foreach ($routes as $route) {
79
            foreach ($route['methods'] as $method) {
80
                $router->match($method, $route['pattern'], fn () => 'Hello');
81
            }
82
        }
83
84
        $this->router = $router;
85
    }
86
}
87