UrlProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getUrl() 0 7 2
A supports() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\Bridge\Url;
6
7
use Everlution\Navigation\Item\ItemInterface;
8
use Everlution\Navigation\Url\UrlProviderInterface;
9
use Everlution\NavigationBundle\Bridge\Item\RoutableInterface;
10
use Symfony\Component\Routing\RouterInterface;
11
12
/**
13
 * Class UrlProvider.
14
 *
15
 * @author Ivan Barlog <[email protected]>
16
 */
17
class UrlProvider implements UrlProviderInterface
18
{
19
    /** @var RouterInterface */
20
    private $router;
21
22
    public function __construct(RouterInterface $router)
23
    {
24
        $this->router = $router;
25
    }
26
27
    /**
28
     * @param ItemInterface $item
29
     *
30
     * @return string
31
     *
32
     * @throws ItemIsNotSupportedException
33
     */
34
    public function getUrl(ItemInterface $item): string
35
    {
36
        if (false === $item instanceof RoutableInterface) {
37
            throw new ItemIsNotSupportedException($item, RouterInterface::class);
38
        }
39
40
        return $this->router->generate($item->getRoute(), $item->getParameters());
41
    }
42
43
    public function supports(ItemInterface $item): bool
44
    {
45
        return $item instanceof RoutableInterface;
46
    }
47
}
48