DomainNameDataSource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 22.41 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 13
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getCurrentDomainName() 0 4 1
A getDomainName() 0 4 1
A getCurrentDomainNameFormParams() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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