WebRouter::match()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 12
ccs 2
cts 2
cp 1
rs 9.9332
c 1
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Router;
6
7
use BEAR\Sunday\Annotation\DefaultSchemeHost;
8
use BEAR\Sunday\Extension\Router\RouterInterface;
9
use BEAR\Sunday\Extension\Router\RouterMatch;
10
use Override;
11
12
use function assert;
13
use function parse_url;
14
15
use const PHP_URL_PATH;
16
17
/**
18
 * @psalm-import-type Globals from RouterInterface
19
 * @psalm-import-type Server from RouterInterface
20
 * @psalm-suppress ClassMustBeFinal
21
 */
22
class WebRouter implements RouterInterface, WebRouterInterface
23
{
24
    public function __construct(
25
        #[DefaultSchemeHost]
26 41
        private string $schemeHost,
27
        private HttpMethodParamsInterface $httpMethodParams,
28 41
    ) {
29 41
    }
30 41
31
    /**
32
     * @param array{HTTP_X_HTTP_METHOD_OVERRIDE?: string, REQUEST_METHOD: string, REQUEST_URI: string, ...} $server
33
     * @param array{_GET: array<string|array>, _POST: array<string|array>}                              $globals
34
     */
35 8
36
    /**
37 8
     * {@inheritDoc}
38 8
     *
39 8
     * @param Globals $globals
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Provide\Router\Globals was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
     * @param Server  $server
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Provide\Router\Server was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41 8
     */
42
    #[Override]
43
    public function match(array $globals, array $server)
44
    {
45
        $requestUri = $server['REQUEST_URI'];
46
        $get = $globals['_GET'];
47 9
        $post = $globals['_POST'];
48
        [$method, $query] = $this->httpMethodParams->get($server, $get, $post);
49 9
        $parsedPath = parse_url($requestUri, PHP_URL_PATH);
50
        assert($parsedPath !== null && $parsedPath !== false);
51
        $path = $this->schemeHost . $parsedPath;
52
53
        return new RouterMatch($method, $path, $query);
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    #[Override]
60
    public function generate($name, $data)
61
    {
62
        return false;
63
    }
64
}
65