UrlProvider::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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