Lottery   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 160
Duplicated Lines 20 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 20
c 0
b 0
f 0
lcom 2
cbo 4
dl 32
loc 160
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDrawAuto() 0 4 1
A setDrawAuto() 0 6 1
A getWinners() 0 4 1
A setWinners() 0 6 1
A getSubstitutes() 0 4 1
A setSubstitutes() 0 6 1
A getDrawDate() 0 4 1
A setDrawDate() 0 6 1
A getArrayCopy() 3 11 3
A populate() 11 11 5
A setInputFilter() 0 4 1
A getInputFilter() 18 18 2

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
namespace PlaygroundGame\Entity;
3
4
use PlaygroundGame\Entity\Game;
5
use Doctrine\ORM\Mapping as ORM;
6
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
7
use Zend\InputFilter\InputFilter;
8
use Zend\InputFilter\Factory as InputFactory;
9
use Zend\InputFilter\InputFilterAwareInterface;
10
use Zend\InputFilter\InputFilterInterface;
11
12
/**
13
 * @ORM\Entity @HasLifecycleCallbacks
14
 * @ORM\Table(name="game_lottery")
15
 */
16
class Lottery extends Game implements InputFilterAwareInterface
17
{
18
    const CLASSTYPE = 'lottery';
19
    /**
20
     * Automatic Draw
21
     * @ORM\Column(name="draw_auto", type="boolean", nullable=false)
22
     */
23
    protected $drawAuto = 0;
24
25
    /**
26
     * @ORM\Column(name="draw_date", type="datetime", nullable=true)
27
     */
28
    protected $drawDate;
29
30
    /**
31
     * @ORM\Column(type="integer", nullable=false)
32
     */
33
    protected $winners;
34
35
    /**
36
     * @ORM\Column(type="integer", nullable=false)
37
     */
38
    protected $substitutes;
39
40
    public function __construct()
41
    {
42
        parent::__construct();
43
        $this->setClassType(self::CLASSTYPE);
44
    }
45
46
    /**
47
     * @return integer
48
     */
49
    public function getDrawAuto()
50
    {
51
        return $this->drawAuto;
52
    }
53
54
    /**
55
     * @param integer $drawAuto
56
     */
57
    public function setDrawAuto($drawAuto)
58
    {
59
        $this->drawAuto = $drawAuto;
60
61
        return $this;
62
    }
63
64
    /**
65
     * @return integer
66
     */
67
    public function getWinners()
68
    {
69
        return $this->winners;
70
    }
71
72
    /**
73
     * @param integer $winners
74
     */
75
    public function setWinners($winners)
76
    {
77
        $this->winners = $winners;
78
79
        return $this;
80
    }
81
82
    /**
83
     * @return integer
84
     */
85
    public function getSubstitutes()
86
    {
87
        return $this->substitutes;
88
    }
89
90
    /**
91
     * @param integer $substitutes
92
     */
93
    public function setSubstitutes($substitutes)
94
    {
95
        $this->substitutes = $substitutes;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @return \DateTime
102
     */
103
    public function getDrawDate()
104
    {
105
        return $this->drawDate;
106
    }
107
108
    /**
109
     * @param \DateTime $drawDate
110
     */
111
    public function setDrawDate($drawDate)
112
    {
113
        $this->drawDate = $drawDate;
114
115
        return $this;
116
    }
117
118
    /**
119
     * Convert the object to an array.
120
     *
121
     * @return array
122
     */
123
    public function getArrayCopy()
124
    {
125
        $obj_vars = parent::getArrayCopy();
126
        array_merge($obj_vars, get_object_vars($this));
127
128 View Code Duplication
        if (isset($obj_vars['drawDate']) && $obj_vars['drawDate'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
129
            $obj_vars['drawDate'] = $obj_vars['drawDate']->format('d/m/Y');
130
        }
131
132
        return $obj_vars;
133
    }
134
135
    /**
136
     * Populate from an array.
137
     *
138
     * @param array $data
139
     */
140 View Code Duplication
    public function populate($data = array())
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...
141
    {
142
        parent::populate($data);
143
144
        if (isset($data['drawAuto']) && $data['drawAuto'] !== null) {
145
            $this->drawAuto = $data['drawAuto'];
146
        }
147
        $this->drawDate = (isset($data['drawDate']) && $data['drawDate'] !== null) ?
148
            \DateTime::createFromFormat('d/m/Y', $data['drawDate']) :
149
            null;
150
    }
151
152
    public function setInputFilter(InputFilterInterface $inputFilter)
153
    {
154
        throw new \Exception("Not used");
155
    }
156
157 View Code Duplication
    public function getInputFilter()
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...
158
    {
159
        if (!$this->inputFilter) {
160
            $inputFilter = new InputFilter();
0 ignored issues
show
Unused Code introduced by
$inputFilter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
161
            $factory = new InputFactory();
162
163
            $inputFilter = parent::getInputFilter();
164
165
            $inputFilter->add($factory->createInput(array(
166
                'name' => 'drawDate',
167
                'required' => false,
168
            )));
169
170
            $this->inputFilter = $inputFilter;
171
        }
172
173
        return $this->inputFilter;
174
    }
175
}
176