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 |
||
17 | class ProfileEntity |
||
18 | extends AbstractImageUpload |
||
|
|||
19 | { |
||
20 | /** |
||
21 | * @var integer |
||
22 | * |
||
23 | * @ORM\Column(name="id", type="integer") |
||
24 | * @ORM\Id |
||
25 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
26 | */ |
||
27 | protected $id; |
||
28 | |||
29 | /** |
||
30 | * Mr., Mrs., Ms., Ing., ... |
||
31 | * |
||
32 | * @var string |
||
33 | * |
||
34 | * @ORM\Column(name="title", type="string", length=8, nullable=true) |
||
35 | */ |
||
36 | protected $title; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * @ORM\Column(name="first_name", type="string", length=32, nullable=true) |
||
42 | */ |
||
43 | protected $firstName; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @ORM\Column(name="middle_name", type="string", length=32, nullable=true) |
||
49 | */ |
||
50 | protected $middleName; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | * |
||
55 | * @ORM\Column(name="last_name", type="string", length=32, nullable=true) |
||
56 | */ |
||
57 | protected $lastName; |
||
58 | |||
59 | /** |
||
60 | * male or female? |
||
61 | * |
||
62 | * @var string |
||
63 | * |
||
64 | * @ORM\Column(name="gender", type="string", length=8, nullable=true) |
||
65 | */ |
||
66 | protected $gender; |
||
67 | |||
68 | /** |
||
69 | * @var \DateTime |
||
70 | * |
||
71 | * @ORM\Column(name="birthdate", type="datetime", nullable=true) |
||
72 | */ |
||
73 | protected $birthdate; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | * |
||
78 | * @ORM\Column(name="image_url", type="text", nullable=true) |
||
79 | */ |
||
80 | protected $imageUrl; |
||
81 | |||
82 | /** |
||
83 | * @ORM\OneToOne(targetEntity="Application\Entity\UserEntity", inversedBy="profile") |
||
84 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id") |
||
85 | */ |
||
86 | protected $user; |
||
87 | |||
88 | /*** Id ***/ |
||
89 | /** |
||
90 | * @return integer |
||
91 | */ |
||
92 | public function getId() |
||
96 | |||
97 | /** |
||
98 | * @param $id |
||
99 | * |
||
100 | * @return ProfileEntity |
||
101 | */ |
||
102 | public function setId($id) |
||
108 | |||
109 | /*** Title ***/ |
||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getTitle() |
||
117 | |||
118 | /** |
||
119 | * @param $title |
||
120 | * |
||
121 | * @return ProfileEntity |
||
122 | */ |
||
123 | public function setTitle($title) |
||
129 | |||
130 | /*** Name ***/ |
||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getName() |
||
138 | |||
139 | /*** First name ***/ |
||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getFirstName() |
||
147 | |||
148 | /** |
||
149 | * @param $firstName |
||
150 | * |
||
151 | * @return ProfileEntity |
||
152 | */ |
||
153 | public function setFirstName($firstName) |
||
159 | |||
160 | /*** Middle name ***/ |
||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getMiddleName() |
||
168 | |||
169 | /** |
||
170 | * @param $middleName |
||
171 | * |
||
172 | * @return ProfileEntity |
||
173 | */ |
||
174 | public function setMiddleName($middleName) |
||
180 | |||
181 | /*** Last name ***/ |
||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getLastName() |
||
189 | |||
190 | /** |
||
191 | * @param $lastName |
||
192 | * |
||
193 | * @return ProfileEntity |
||
194 | */ |
||
195 | public function setLastName($lastName) |
||
201 | |||
202 | /*** Full name ***/ |
||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | public function getFullName() |
||
215 | |||
216 | /*** Gender ***/ |
||
217 | /** |
||
218 | * @return string |
||
219 | */ |
||
220 | public function getGender() |
||
224 | |||
225 | /** |
||
226 | * @param $gender |
||
227 | * |
||
228 | * @return ProfileEntity |
||
229 | */ |
||
230 | public function setGender($gender) |
||
236 | |||
237 | /*** Birthdate ***/ |
||
238 | /** |
||
239 | * @return string |
||
240 | */ |
||
241 | public function getBirthdate() |
||
245 | |||
246 | /** |
||
247 | * @param mixed $birthdate |
||
248 | * |
||
249 | * @return ProfileEntity |
||
250 | */ |
||
251 | public function setBirthdate($birthdate = null) |
||
263 | |||
264 | /*** Age ***/ |
||
265 | /** |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getAge($format = '%y') |
||
275 | |||
276 | /*** Image upload ***/ |
||
277 | /** |
||
278 | * @return ProfileEntity |
||
279 | * |
||
280 | * @throws \Exception If upload dir and path are not set |
||
281 | */ |
||
282 | View Code Duplication | public function imageUpload() |
|
314 | |||
315 | /*** User ***/ |
||
316 | /** |
||
317 | * @return UserEntity |
||
318 | */ |
||
319 | public function getUser() |
||
323 | |||
324 | /** |
||
325 | * @param UserEntity $user |
||
326 | * |
||
327 | * @return ProfileEntity |
||
328 | */ |
||
329 | public function setUser(UserEntity $user) |
||
335 | |||
336 | /** |
||
337 | * @return array |
||
338 | */ |
||
339 | public function toArray() |
||
355 | } |
||
356 |