WebRouter::match()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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
11
use function parse_url;
12
13
/**
14
 * @psalm-import-type Globals from RouterInterface
15
 * @psalm-import-type Server from RouterInterface
16
 */
17
class WebRouter implements RouterInterface, WebRouterInterface
18
{
19
    public function __construct(
20
        #[DefaultSchemeHost]
21
        private string $schemeHost,
22
        private HttpMethodParamsInterface $httpMethodParams,
23
    ) {
24
    }
25
26 41
    /**
27
     * @param array{HTTP_X_HTTP_METHOD_OVERRIDE?: string, REQUEST_METHOD: string, REQUEST_URI: string, ...} $server
28 41
     * @param array{_GET: array<string|array>, _POST: array<string|array>}                              $globals
29 41
     */
30 41
31
    /**
32
     * {@inheritDoc}
33
     *
34
     * @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...
35 8
     * @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...
36
     */
37 8
    public function match(array $globals, array $server)
38 8
    {
39 8
        $requestUri = $server['REQUEST_URI'];
40
        $get = $globals['_GET'];
41 8
        $post = $globals['_POST'];
42
        [$method, $query] = $this->httpMethodParams->get($server, $get, $post);
43
        $path = $this->schemeHost . parse_url($requestUri, 5); // 5 = PHP_URL_PATH
44
45
        return new RouterMatch($method, $path, $query);
46
    }
47 9
48
    /**
49 9
     * {@inheritDoc}
50
     */
51
    public function generate($name, $data)
52
    {
53
        return false;
54
    }
55
}
56