Completed
Pull Request — master (#375)
by Paul
06:22
created

RequestDataSource   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 2
cbo 1
dl 0
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getLocale() 0 4 1
A getScheme() 0 4 1
A getLocaleFormParams() 0 9 1
A getSchemeFormParams() 0 12 1
1
<?php
2
3
namespace Victoire\Bundle\CriteriaBundle\DataSource;
4
5
6
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
9
class RequestDataSource
10
{
11
    /**
12
     * @var RequestStack
13
     */
14
    private $requestStack;
15
    private $availableLocales;
16
17
    /**
18
     * RequestCriteria constructor.
19
     *
20
     * @param RequestStack $requestStack
21
     * @param              $availableLocales
22
     */
23
    public function __construct(RequestStack $requestStack, $availableLocales)
24
    {
25
        $this->requestStack = $requestStack;
26
        $this->availableLocales = $availableLocales;
27
    }
28
29
    public function getLocale()
30
    {
31
        return $this->requestStack->getCurrentRequest()->getLocale();
32
    }
33
34
    public function getScheme()
35
    {
36
        return $this->requestStack->getCurrentRequest()->getScheme();
37
    }
38
39
40
    public function getLocaleFormParams()
41
    {
42
        return [
43
            'type' => ChoiceType::class,
44
            'options' => [
45
                'choices' => $this->availableLocales,
46
            ]
47
        ];
48
    }
49
    public function getSchemeFormParams()
50
    {
51
        return [
52
            'type' => ChoiceType::class,
53
            'options' => [
54
                'choices' => [
55
                    'http' => 'http',
56
                    'https' => 'https'
57
                ],
58
            ]
59
        ];
60
    }
61
}
62