Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

LocaleSwitcherTwigExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 72
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 8 1
A renderWidget() 0 16 1
A getLocales() 0 4 1
A getBackendLocales() 0 4 1
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Twig;
4
5
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
6
7
/**
8
 * LocaleSwitcherTwigExtension
9
 */
10
class LocaleSwitcherTwigExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
11
{
12
    /**
13
     * @var DomainConfigurationInterface
14
     */
15
    private $domainConfiguration;
16
17
    /**
18
     * @param DomainConfigurationInterface $domainConfiguration
19
     */
20
    public function __construct(DomainConfigurationInterface $domainConfiguration)
21
    {
22
        $this->domainConfiguration = $domainConfiguration;
23
    }
24
25
    /**
26
     * Get Twig functions defined in this extension.
27
     *
28
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Twig_SimpleFunction[].

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...
29
     */
30
    public function getFunctions()
31
    {
32
        return array(
33
            new \Twig_SimpleFunction('localeswitcher_widget', array($this, 'renderWidget'), array('needs_environment' => true, 'is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
34
            new \Twig_SimpleFunction('get_locales', array($this, 'getLocales')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
            new \Twig_SimpleFunction('get_backend_locales', array($this, 'getBackendLocales')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36
        );
37
    }
38
39
    /**
40
     * Render locale switcher widget.
41
     *
42
     * @param \Twig_Environment $env
43
     * @param array             $locales    The locales
44
     * @param string            $route      The route
45
     * @param array             $parameters The route parameters
46
     *
47
     * @return string
48
     */
49
    public function renderWidget(\Twig_Environment $env, $locales, $route, array $parameters = array())
50
    {
51
        $template = $env->loadTemplate(
52
            'KunstmaanAdminBundle:LocaleSwitcherTwigExtension:widget.html.twig'
53
        );
54
55
        return $template->render(
56
            array_merge(
57
                $parameters,
58
                array(
59
                    'locales' => $locales,
60
                    'route' => $route,
61
                )
62
            )
63
        );
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getLocales()
70
    {
71
        return $this->domainConfiguration->getFrontendLocales();
72
    }
73
74
    /**
75
     * @return array
76
     */
77
    public function getBackendLocales($switchedHost = null)
78
    {
79
        return $this->domainConfiguration->getBackendLocales($switchedHost);
80
    }
81
}
82