Completed
Push — master ( 89f754...0e5042 )
by Michael
03:54
created

Poll   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 241
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 1
dl 0
loc 241
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 4 1
A setName() 0 6 1
A getName() 0 4 1
A setStart() 0 6 1
A getStart() 0 4 1
A setDescription() 0 6 1
A getDescription() 0 4 1
A setCreator() 0 6 1
A getCreator() 0 4 1
A addVote() 0 6 1
A removeVote() 0 4 1
A getVotes() 0 4 1
A addChoice() 0 6 1
A removeChoice() 0 4 1
A getChoices() 0 4 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use AppBundle\Entity\User;
7
use AppBundle\Entity\Vote;
8
use Doctrine\Common\Collections\ArrayCollection;
9
10
/**
11
 * Poll
12
 *
13
 * @ORM\Table(name="polls")
14
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PollRepository")
15
 */
16
class Poll
17
{
18
    /**
19
     * @var int
20
     *
21
     * @ORM\Column(name="id", type="integer")
22
     * @ORM\Id
23
     * @ORM\GeneratedValue(strategy="AUTO")
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(name="name", type="string", length=255)
31
     */
32
    private $name;
33
34
    /**
35
     * @var \DateTime
36
     *
37
     * @ORM\Column(name="start", type="datetime")
38
     */
39
    private $start;
40
41
    /**
42
     * @var \User
43
     *
44
     * @ORM\ManyToOne(targetEntity="User", inversedBy="polls")
45
     * @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
46
     */
47
    private $creator;
48
49
    /**
50
     * @var \PollType
51
     *
52
     * @ORM\ManyToOne(targetEntity="PollType", inversedBy="polls")
53
     * @ORM\JoinColumn(name="poll_type_id", referencedColumnName="id")
54
     */
55
    private $pollType;
56
57
    /**
58
     * @var string
59
     *
60
     * @ORM\Column(name="description", type="text", nullable=true)
61
     */
62
    private $description;
63
64
    /**
65
     * @ORM\OneToMany(targetEntity="Vote", mappedBy="poll")
66
     */
67
    private $votes;
68
69
    /**
70
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Choice")
71
     */
72
    private $choices;
73
74
    /**
75
     * Constructor
76
     */
77
    public function __construct()
78
    {
79
        $this->votes = new ArrayCollection();
80
        $this->choices = new ArrayCollection();
81
    }
82
83
    /**
84
     * Get id
85
     *
86
     * @return integer
87
     */
88
    public function getId(): int
89
    {
90
        return $this->id;
91
    }
92
93
    /**
94
     * Set name
95
     *
96
     * @param string $name
97
     *
98
     * @return Poll
99
     */
100
    public function setName(string $name)
101
    {
102
        $this->name = $name;
103
104
        return $this;
105
    }
106
107
    /**
108
     * Get name
109
     *
110
     * @return string
111
     */
112
    public function getName(): string
113
    {
114
        return $this->name;
115
    }
116
117
    /**
118
     * Set start
119
     *
120
     * @param \DateTime $start
121
     *
122
     * @return Poll
123
     */
124
    public function setStart(\DateTimeInterface $start)
125
    {
126
        $this->start = $start;
0 ignored issues
show
Documentation Bug introduced by
$start is of type object<DateTimeInterface>, but the property $start was declared to be of type object<DateTime>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
127
128
        return $this;
129
    }
130
131
    /**
132
     * Get start
133
     *
134
     * @return \DateTime
135
     */
136
    public function getStart(): DateTime
137
    {
138
        return $this->start;
139
    }
140
141
    /**
142
     * Set description
143
     *
144
     * @param string $description
145
     *
146
     * @return Poll
147
     */
148
    public function setDescription(string $description)
149
    {
150
        $this->description = $description;
151
152
        return $this;
153
    }
154
155
    /**
156
     * Get description
157
     *
158
     * @return string
159
     */
160
    public function getDescription(): string
161
    {
162
        return $this->description;
163
    }
164
165
    /**
166
     * Set creator
167
     *
168
     * @param \AppBundle\Entity\User $creator
169
     *
170
     * @return Poll
171
     */
172
    public function setCreator(User $creator = null)
173
    {
174
        $this->creator = $creator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $creator can also be of type object<AppBundle\Entity\User>. However, the property $creator is declared as type object<User>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
175
176
        return $this;
177
    }
178
179
    /**
180
     * Get creator
181
     *
182
     * @return \AppBundle\Entity\User
183
     */
184
    public function getCreator(): User
185
    {
186
        return $this->creator;
187
    }
188
189
    /**
190
     * Add vote
191
     *
192
     * @param \AppBundle\Entity\Vote $vote
193
     *
194
     * @return Poll
195
     */
196
    public function addVote(Vote $vote)
197
    {
198
        $this->votes[] = $vote;
199
200
        return $this;
201
    }
202
203
    /**
204
     * Remove vote
205
     *
206
     * @param \AppBundle\Entity\Vote $vote
207
     */
208
    public function removeVote(Vote $vote)
209
    {
210
        $this->votes->removeElement($vote);
211
    }
212
213
    /**
214
     * Get votes
215
     *
216
     * @return \Doctrine\Common\Collections\Collection
217
     */
218
    public function getVotes()
219
    {
220
        return $this->votes;
221
    }
222
223
    /**
224
     * Add choice
225
     *
226
     * @param \AppBundle\Entity\Choice $choice
227
     *
228
     * @return Poll
229
     */
230
    public function addChoice(Choice $choice)
231
    {
232
        $this->choices[] = $choice;
233
234
        return $this;
235
    }
236
237
    /**
238
     * Remove choice
239
     *
240
     * @param \AppBundle\Entity\Choice $choice
241
     */
242
    public function removeChoice(Choice $choice)
243
    {
244
        $this->choices->removeElement($choice);
245
    }
246
247
    /**
248
     * Get choices
249
     *
250
     * @return \Doctrine\Common\Collections\Collection
251
     */
252
    public function getChoices()
253
    {
254
        return $this->choices;
255
    }
256
}
257