LocaleExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A getLocalePreferenceForm() 0 12 1
A getName() 0 4 1
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\Twig;
20
21
use OpenConext\Profile\Assert;
22
use OpenConext\ProfileBundle\Form\Type\SwitchLocaleType;
23
use Symfony\Component\Form\FormFactoryInterface;
24
use Twig_Extension as Extension;
25
use Twig_SimpleFunction as SimpleFunction;
26
27
final class LocaleExtension extends Extension
28
{
29
    /**
30
     * @var \Symfony\Component\Form\FormFactoryInterface
31
     */
32
    private $formFactory;
33
34
    public function __construct(FormFactoryInterface $formFactory)
35
    {
36
        $this->formFactory = $formFactory;
37
    }
38
39
    public function getFunctions()
40
    {
41
        return [
42
            new SimpleFunction('profile_locale_switcher', [$this, 'getLocalePreferenceForm'])
43
        ];
44
    }
45
46
    /**
47
     * @param string $returnUrl
48
     * @return \Symfony\Component\Form\FormView
49
     */
50
    public function getLocalePreferenceForm($returnUrl)
51
    {
52
        Assert::string($returnUrl);
53
54
        $form = $this->formFactory->create(
55
            SwitchLocaleType::class,
56
            null,
57
            ['return_url' => $returnUrl]
58
        );
59
60
        return $form->createView();
61
    }
62
63
    public function getName()
64
    {
65
        return 'profile_locale';
66
    }
67
}
68