MultiDomainTwigExtension::getExtraData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Kunstmaan\MultiDomainBundle\Twig;
4
5
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
6
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFunction;
8
9
/**
10
 * @final since 5.4
11
 */
12
class MultiDomainTwigExtension extends AbstractExtension
13
{
14
    /**
15
     * @var DomainConfigurationInterface
16
     */
17
    private $domainConfiguration;
18
19
    public function __construct(DomainConfigurationInterface $domainConfiguration)
20
    {
21
        $this->domainConfiguration = $domainConfiguration;
22
    }
23
24
    /**
25
     * Get Twig functions defined in this extension.
26
     *
27
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use TwigFunction[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
28
     */
29
    public function getFunctions()
30
    {
31
        return array(
32
            new TwigFunction('get_multi_domain_hosts', array($this, 'getMultiDomainHosts')),
33
            new TwigFunction('get_current_host', array($this, 'getCurrentHost')),
34
            new TwigFunction('get_extra_data', array($this, 'getExtraData')),
35
            new TwigFunction('get_current_full_host', array($this, 'getCurrentFullHost')),
36
        );
37
    }
38
39
    /**
40
     * @param $key
41
     */
42
    public function getExtraData($key)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44
        $extraData = $this->domainConfiguration->getExtraData();
45
46
        if ($extraData[$key]) {
47
            return $extraData[$key];
48
        }
49
50
        return null;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getMultiDomainHosts()
57
    {
58
        return $this->domainConfiguration->getHosts();
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getCurrentHost()
65
    {
66
        return $this->domainConfiguration->getHost();
67
    }
68
69
    /**
70
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
71
     */
72
    public function getCurrentFullHost()
73
    {
74
        return $this->domainConfiguration->getFullHost();
75
    }
76
}
77