Completed
Push — master ( 64470f...3a69fd )
by Florian
02:24
created

Parameters   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 97
Duplicated Lines 29.9 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 29
loc 97
wmc 14
lcom 1
cbo 1
ccs 38
cts 38
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getParameters() 0 4 1
A getFilter() 0 4 1
A setFilter() 0 6 1
A setLang() 0 6 1
A getLang() 0 4 1
A getFilterColumn() 15 15 4
A getFilterValue() 14 14 4

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 Laposte\DatanovaBundle\Model;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
/**
8
 * @author Florian Ajir <[email protected]>
9
 */
10
abstract class Parameters extends ParameterBag
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 6
    public function __construct(array $parameters = array())
16
    {
17 6
        parent::__construct($parameters);
18 6
    }
19
20
    /**
21
     * @return array
22
     */
23 2
    public function getParameters()
24
    {
25 2
        return $this->parameters;
26
    }
27
28
    /**
29
     * @return string $query
30
     */
31 2
    public function getFilter()
32
    {
33 2
        return $this->get('q');
34
    }
35
36
    /**
37
     * @param string $query
38
     *
39
     * @return $this
40
     */
41 2
    public function setFilter($query)
42
    {
43 2
        $this->set('q', $query);
44
45 2
        return $this;
46
    }
47
48
    /**
49
     * @param $lang
50
     *
51
     * @return self
52
     */
53 1
    public function setLang($lang)
54
    {
55 1
        $this->set('lang', $lang);
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    public function getLang()
64
    {
65 1
        return $this->get('lang');
66
    }
67
68
    /**
69
     * Get column prefix of a query
70
     *
71
     * @return string
72
     */
73 2 View Code Duplication
    public function getFilterColumn()
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...
74
    {
75 2
        $columnFilter = null;
76 2
        $query = $this->parameters['q'];
77 2
        if (false !== strpos($query, ':')) {
78 1
            $explode = explode(':', $query);
79 2
        } elseif (false !== strpos($query, '=')) {
80 1
            $explode = explode('=', $query);
81 1
        }
82 2
        if (isset($explode[0])) {
83 2
            $columnFilter = $explode[0];
84 2
        }
85
86 2
        return $columnFilter;
87
    }
88
89
    /**
90
     * @return string
91
     */
92 2 View Code Duplication
    public function getFilterValue()
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...
93
    {
94 2
        $valueFilter = $query = $this->parameters['q'];
95 2
        if (false !== strpos($query, ':')) {
96 1
            $explode = explode(':', $query);
97 2
        } elseif (false !== strpos($query, '=')) {
98 1
            $explode = explode('=', $query);
99 1
        }
100 2
        if (isset($explode[1])) {
101 2
            $valueFilter = $explode[1];
102 2
        }
103
104 2
        return $valueFilter;
105
    }
106
}
107