1 | <?php |
||
16 | class Survey |
||
17 | { |
||
18 | use ORMBehaviors\Timestampable\Timestampable; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | * |
||
23 | * @ORM\Column(type="integer") |
||
24 | * @ORM\Id |
||
25 | * @ORM\GeneratedValue(strategy="AUTO") |
||
26 | */ |
||
27 | private $id; |
||
28 | |||
29 | /** |
||
30 | * @var SurveyType |
||
31 | * @Assert\Type("object") |
||
32 | * @Assert\Valid |
||
33 | * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Survey\SurveyType", inversedBy="surveys") |
||
34 | * @ORM\JoinColumn(onDelete="SET NULL") |
||
35 | */ |
||
36 | private $type; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * @Assert\NotBlank() |
||
41 | * @Assert\Type("string") |
||
42 | * @ORM\Column(type="string") |
||
43 | */ |
||
44 | private $status; |
||
45 | |||
46 | /** |
||
47 | * @var bool |
||
48 | * @Assert\Type("bool") |
||
49 | * @ORM\Column(type="boolean") |
||
50 | */ |
||
51 | private $reviewed; |
||
52 | |||
53 | /** |
||
54 | * @var User |
||
55 | * @Assert\Type("object") |
||
56 | * @Assert\Valid |
||
57 | * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="surveys") |
||
58 | * @ORM\JoinColumn(onDelete="CASCADE") |
||
59 | */ |
||
60 | private $user; |
||
61 | |||
62 | /** |
||
63 | * @var ArrayCollection[SurveyAnswer] |
||
64 | * @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="survey", cascade={"persist", "remove"}) |
||
65 | */ |
||
66 | private $answers; |
||
67 | |||
68 | 1 | public function __construct() |
|
69 | { |
||
70 | 1 | $this->answers = new ArrayCollection(); |
|
71 | 1 | $this->status = 'current'; |
|
72 | 1 | $this->reviewed = false; |
|
73 | 1 | } |
|
74 | |||
75 | /** |
||
76 | * Get id. |
||
77 | * |
||
78 | * @return int |
||
79 | */ |
||
80 | 2 | public function getId() |
|
84 | |||
85 | /** |
||
86 | * Set type. |
||
87 | * |
||
88 | * @param SurveyType $type |
||
89 | * |
||
90 | * @return Survey |
||
91 | */ |
||
92 | 1 | public function setType(SurveyType $type) |
|
98 | |||
99 | /** |
||
100 | * Get type. |
||
101 | * |
||
102 | * @return SurveyType |
||
103 | */ |
||
104 | 6 | public function getType() |
|
108 | |||
109 | /** |
||
110 | * Set status. |
||
111 | * |
||
112 | * @param string $status |
||
113 | * |
||
114 | * @return Survey |
||
115 | */ |
||
116 | 1 | public function setStatus($status) |
|
122 | |||
123 | /** |
||
124 | * Get status. |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 3 | public function getStatus() |
|
132 | |||
133 | /** |
||
134 | * Set review. |
||
135 | * |
||
136 | * @param bool $review |
||
137 | * |
||
138 | * @return Survey |
||
139 | */ |
||
140 | 1 | public function setReviewed($review) |
|
146 | |||
147 | /** |
||
148 | * Get review. |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | 1 | public function isReviewed() |
|
156 | |||
157 | /** |
||
158 | * Set user. |
||
159 | * |
||
160 | * @param User $user |
||
161 | * |
||
162 | * @return Survey |
||
163 | */ |
||
164 | 1 | public function setUser(User $user) |
|
170 | |||
171 | /** |
||
172 | * Get user. |
||
173 | * |
||
174 | * @return User |
||
175 | */ |
||
176 | 4 | public function getUser() |
|
180 | |||
181 | /** |
||
182 | * @param SurveyAnswer $answer |
||
183 | * |
||
184 | * @return Survey |
||
185 | */ |
||
186 | public function addSurveyAnswer(SurveyAnswer $answer) |
||
195 | |||
196 | /** |
||
197 | * Get answers. |
||
198 | * |
||
199 | * @return ArrayCollection |
||
200 | */ |
||
201 | public function getAnswers() |
||
205 | |||
206 | /** |
||
207 | * Get questions. |
||
208 | * |
||
209 | * @return array |
||
210 | */ |
||
211 | 1 | public function getQuestions() |
|
222 | |||
223 | /** |
||
224 | * Add answer |
||
225 | * |
||
226 | * @param \AppBundle\Entity\Survey\SurveyAnswer $answer |
||
227 | * |
||
228 | * @return Survey |
||
229 | */ |
||
230 | public function addAnswer(\AppBundle\Entity\Survey\SurveyAnswer $answer) |
||
236 | |||
237 | /** |
||
238 | * Remove answer |
||
239 | * |
||
240 | * @param \AppBundle\Entity\Survey\SurveyAnswer $answer |
||
241 | */ |
||
242 | public function removeAnswer(\AppBundle\Entity\Survey\SurveyAnswer $answer) |
||
246 | } |
||
247 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.