Completed
Push — master ( 7b2ae7...b60607 )
by Dominik
06:56
created

LinkGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateLink() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Serialization;
6
7
use Chubbyphp\Serialization\Link\Link;
8
use Chubbyphp\Serialization\Link\LinkGeneratorInterface;
9
use Chubbyphp\Serialization\Link\LinkInterface;
10
use Psr\Http\Message\ServerRequestInterface as Request;
11
use Slim\Interfaces\RouterInterface;
12
use Slim\Route;
13
14
final class LinkGenerator implements LinkGeneratorInterface
15
{
16
    /**
17
     * @var RouterInterface
18
     */
19
    private $router;
20
21
    /**
22
     * @param RouterInterface $router
23
     */
24 1
    public function __construct(RouterInterface $router)
25
    {
26 1
        $this->router = $router;
27 1
    }
28
29
    /**
30
     * @param string $routeName
31
     * @param array  $data
32
     * @param array  $queryParams
33
     *
34
     * @return LinkInterface
35
     */
36 1
    public function generateLink(
37
        Request $request,
38
        string $routeName,
39
        array $data = [],
40
        array $queryParams = []
41
    ): LinkInterface {
42
        /** @var Route $route */
43 1
        $route = $this->router->getNamedRoute($routeName);
44
45 1
        return new Link(
46 1
            $this->router->pathFor($routeName, $data, $queryParams),
47 1
            implode('|', $route->getMethods())
48
        );
49
    }
50
}
51