DomainNameDataSource::getCurrentDomainName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Victoire\Bundle\CriteriaBundle\DataSource;
4
5
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
/**
9
 * Class DomainNameDataSource.
10
 */
11
class DomainNameDataSource
12
{
13
    /**
14
     * @var array
15
     */
16
    private $domainName;
17
    /**
18
     * @var RequestStack
19
     */
20
    private $requestStack;
21
22
    /**
23
     * DomainNameDataSource constructor.
24
     *
25
     * @param array        $domainName
26
     * @param RequestStack $requestStack
27
     */
28
    public function __construct(
29
        array $domainName,
30
        RequestStack $requestStack
31
    ) {
32
        $this->domainName = $domainName;
33
        $this->requestStack = $requestStack;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getCurrentDomainName()
40
    {
41
        return $this->requestStack->getCurrentRequest()->getHost();
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function getDomainName()
48
    {
49
        return $this->domainName[0];
50
    }
51
52
    /**
53
     * @return array
54
     */
55 View Code Duplication
    public function getCurrentDomainNameFormParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        return [
58
            'type'    => ChoiceType::class,
59
            'options' => [
60
                'choices'           => $this->getDomainName(),
61
                'choices_as_values' => true,
62
                'choice_label'      => function ($value) {
63
                    return $value;
64
                },
65
            ],
66
        ];
67
    }
68
}
69