Passed
Pull Request — master (#13)
by
unknown
02:49
created

ItemHelper::getLabel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Everlution\NavigationBundle\Twig;
4
5
use Everlution\Bridge\Symfony\Translator\TranslatorInterface;
0 ignored issues
show
Bug introduced by
The type Everlution\Bridge\Symfon...tor\TranslatorInterface 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...
6
use Everlution\Navigation\Item\ItemInterface;
7
use Everlution\Navigation\Url\CannotProvideUrlForItemException;
8
use Everlution\Navigation\Url\UrlProviderContainer;
9
use Everlution\NavigationBundle\Bridge\Item\TranslatableItemLabelInterface;
10
11
/**
12
 * Class Helper
13
 * @author Martin Lutter <[email protected]>
14
 */
15
class ItemHelper
16
{
17
    /** @var TranslatorInterface */
18
    private $translator;
19
    /** @var UrlProviderContainer */
20
    private $urlProvider;
21
22
    public function __construct(TranslatorInterface $translator, UrlProviderContainer $urlProvider)
23
    {
24
        $this->translator = $translator;
25
        $this->urlProvider = $urlProvider;
26
    }
27
28
    public function getLabel(ItemInterface $item, string $domain = null, string $locale = null): string
29
    {
30
        $label = $item->getLabel();
31
        $parameters = $label instanceof TranslatableItemLabelInterface ? $label->getParameters() : [];
32
33
        return $this->translator->trans($label->getValue(), $parameters, $domain, $locale);
34
    }
35
36
    public function getUrl(ItemInterface $item): string
37
    {
38
        try {
39
            return $this->urlProvider->getUrl($item);
40
        } catch (CannotProvideUrlForItemException $exception) {
41
            return '#';
42
        }
43
    }
44
}
45