RequestDataSource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 22.81 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocale() 0 4 1
A getScheme() 0 4 1
A __construct() 0 5 1
A getLocaleFormParams() 13 13 1
A getSchemeFormParams() 0 12 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
class RequestDataSource
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
9
{
10
    /**
11
     * @var RequestStack
12
     */
13
    private $requestStack;
14
    private $availableLocales;
15
16
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$availableLocales" missing
Loading history...
17
     * RequestCriteria constructor.
18
     *
19
     * @param RequestStack $requestStack
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
20
     * @param              $availableLocales
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
21
     */
22
    public function __construct(RequestStack $requestStack, $availableLocales)
23
    {
24
        $this->requestStack = $requestStack;
25
        $this->availableLocales = $availableLocales;
26
    }
27
28
    public function getLocale()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
29
    {
30
        return $this->requestStack->getCurrentRequest()->getLocale();
31
    }
32
33
    public function getScheme()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
34
    {
35
        return $this->requestStack->getCurrentRequest()->getScheme();
36
    }
37
38 View Code Duplication
    public function getLocaleFormParams()
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...
introduced by
Missing function doc comment
Loading history...
39
    {
40
        return [
41
            'type'    => ChoiceType::class,
42
            'options' => [
43
                'choices'           => $this->availableLocales,
44
                'choices_as_values' => true,
45
                'choice_label'      => function ($value) {
46
                    return $value;
47
                },
48
            ],
49
        ];
50
    }
51
52
    public function getSchemeFormParams()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
53
    {
54
        return [
55
            'type'    => ChoiceType::class,
56
            'options' => [
57
                'choices' => [
58
                    'http'  => 'http',
59
                    'https' => 'https',
60
                ],
61
            ],
62
        ];
63
    }
64
}
65