Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

Twig/MultiDomainTwigExtension.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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
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