Passed
Push — reverse_link ( 4c2b81 )
by Akihito
10:49
created

RouterReverseLinker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Representation;
6
7
use BEAR\Resource\ReverseLinkerInterface;
0 ignored issues
show
Bug introduced by
The type BEAR\Resource\ReverseLinkerInterface 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...
8
use BEAR\Sunday\Extension\Router\RouterInterface;
9
10
use function is_string;
11
use function parse_url;
12
13
use const PHP_URL_PATH;
14
15
final class RouterReverseLinker implements ReverseLinkerInterface
16
{
17
    public function __construct(
18
        private RouterInterface $router,
19
    ) {
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function __invoke(string $uri, array $query): string
26
    {
27
        $routeName = (string) parse_url($uri, PHP_URL_PATH);
28
29
        $reverseUri = $this->router->generate($routeName, $query);
30
        if (is_string($reverseUri)) {
31
            return $reverseUri;
32
        }
33
34
        return $uri;
35
    }
36
}
37