Complex classes like Member often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Member, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
41 | class Member extends Model implements AuthenticatableInterface, CanResetPasswordInterface |
||
42 | { |
||
43 | use Authenticatable, CanResetPassword; |
||
44 | |||
45 | protected $table = 'members'; |
||
46 | |||
47 | protected $hidden = ['password', 'remember_token']; |
||
48 | |||
49 | protected $appends = ['full_name', 'membership_status', 'membership_expiration_date']; |
||
50 | |||
51 | protected $dates = ['birthday']; |
||
52 | |||
53 | public function getId() |
||
57 | |||
58 | public function getEmail() |
||
62 | |||
63 | /** |
||
64 | * @param string $email |
||
65 | */ |
||
66 | public function setEmail($email) |
||
70 | |||
71 | public function getPassword() |
||
75 | |||
76 | /** |
||
77 | * @param string $password |
||
78 | */ |
||
79 | public function setPassword($password) |
||
83 | |||
84 | public function getFirstName() |
||
88 | |||
89 | /** |
||
90 | * @param string $firstName |
||
91 | */ |
||
92 | public function setFirstName($firstName) |
||
96 | |||
97 | public function getLastName() |
||
101 | |||
102 | /** |
||
103 | * @param string $lastName |
||
104 | */ |
||
105 | public function setLastName($lastName) |
||
109 | |||
110 | public function getFullName() |
||
114 | |||
115 | public function faculty() |
||
119 | |||
120 | /** |
||
121 | * @return Faculty |
||
122 | */ |
||
123 | public function getFaculty() |
||
127 | |||
128 | public function setFaculty(Faculty $faculty) |
||
132 | |||
133 | public function getFieldOfStudy() |
||
137 | |||
138 | /** |
||
139 | * @param string $field |
||
140 | */ |
||
141 | public function setFieldOfStudy($field) |
||
145 | |||
146 | public function getYearOfGraduation() |
||
150 | |||
151 | /** |
||
152 | * @param int $year |
||
153 | */ |
||
154 | public function setYearOfGraduation($year) |
||
158 | |||
159 | public function getPhoto() |
||
165 | |||
166 | /** |
||
167 | * @param string $photoFileName |
||
168 | */ |
||
169 | public function setPhoto($photoFileName) |
||
173 | |||
174 | /** |
||
175 | * @return Carbon |
||
176 | */ |
||
177 | public function getBirthday() |
||
181 | |||
182 | public function setBirthday(DateTime $birthday) |
||
186 | |||
187 | /** |
||
188 | * @return int |
||
189 | */ |
||
190 | public function getAge() |
||
194 | |||
195 | public function isBoardMember() |
||
199 | |||
200 | /** |
||
201 | * @param boolean $isBoardMember |
||
202 | */ |
||
203 | public function setBoardMember($isBoardMember) |
||
207 | |||
208 | public function getPositionTitle() |
||
212 | |||
213 | /** |
||
214 | * @param string $title |
||
215 | */ |
||
216 | public function setPositionTitle($title) |
||
220 | |||
221 | /** |
||
222 | * @return Carbon |
||
223 | */ |
||
224 | public function getCreatedAt() |
||
228 | |||
229 | /** |
||
230 | * @return Carbon |
||
231 | */ |
||
232 | public function getUpdatedAt() |
||
236 | |||
237 | public function getFacebook() |
||
241 | |||
242 | /** |
||
243 | * @param string $profile |
||
244 | */ |
||
245 | public function setFacebook($profile) |
||
249 | |||
250 | public function getTwitter() |
||
254 | |||
255 | /** |
||
256 | * @param string $profile |
||
257 | */ |
||
258 | public function setTwitter($profile) |
||
262 | |||
263 | public function getGooglePlus() |
||
267 | |||
268 | /** |
||
269 | * @param string $profile |
||
270 | */ |
||
271 | public function setGooglePlus($profile) |
||
275 | |||
276 | public function getPhoneNumber() |
||
280 | |||
281 | /** |
||
282 | * @param string $number |
||
283 | */ |
||
284 | public function setPhoneNumber($number) |
||
288 | |||
289 | public function getWebsite() |
||
293 | |||
294 | /** |
||
295 | * @param string $url |
||
296 | */ |
||
297 | public function setWebsite($url) |
||
301 | |||
302 | public function isAlumniMember() |
||
306 | |||
307 | /** |
||
308 | * @param boolean $isAlumni |
||
309 | */ |
||
310 | public function setAlumniMember($isAlumni) |
||
314 | |||
315 | public function isApproved() |
||
319 | |||
320 | /** |
||
321 | * @param boolean $isApproved |
||
322 | */ |
||
323 | public function setApproved($isApproved) |
||
327 | |||
328 | /** |
||
329 | * Membership fees paid by the member |
||
330 | * |
||
331 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
332 | */ |
||
333 | public function fees() |
||
337 | |||
338 | /** |
||
339 | * @return Fee[] |
||
340 | */ |
||
341 | public function getFees() |
||
345 | |||
346 | /** |
||
347 | * @return Carbon |
||
348 | */ |
||
349 | public function getExpirationDate() |
||
355 | |||
356 | /** |
||
357 | * @return Carbon |
||
358 | */ |
||
359 | public function getJoiningDate() |
||
365 | |||
366 | /** |
||
367 | * @param string $order ASC or DESC |
||
368 | * @return Fee |
||
369 | */ |
||
370 | private function getFeeByOrder($order) |
||
376 | |||
377 | /** |
||
378 | * @return Fee |
||
379 | */ |
||
380 | public function getLatestFee() |
||
384 | |||
385 | /** |
||
386 | * @return Fee |
||
387 | */ |
||
388 | public function getFirstFee() |
||
392 | |||
393 | /** |
||
394 | * @return bool |
||
395 | */ |
||
396 | public function isActive() |
||
408 | |||
409 | /** |
||
410 | * @return string |
||
411 | */ |
||
412 | public function getMembershipStatus() |
||
416 | |||
417 | /** |
||
418 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
419 | */ |
||
420 | public function attendedMeetings() |
||
424 | |||
425 | /** |
||
426 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
427 | */ |
||
428 | public function createdMeetings() |
||
432 | } |
||
433 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.