Complex classes like User 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 User, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
12 | abstract class User extends AbstractResource implements UserInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | protected $id; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $id_str; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $screen_name; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $location; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | //protected $profile_location; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $description; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $url; |
||
53 | |||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | protected $protected; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $followers_count; |
||
63 | |||
64 | /** |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $friends_count; |
||
68 | |||
69 | /** |
||
70 | * @var int |
||
71 | */ |
||
72 | protected $listed_count; |
||
73 | |||
74 | /** |
||
75 | * @var DateTime |
||
76 | */ |
||
77 | protected $created_at; |
||
78 | |||
79 | /** |
||
80 | * @var int |
||
81 | */ |
||
82 | protected $favourites_count; |
||
83 | |||
84 | /** |
||
85 | * @var int |
||
86 | */ |
||
87 | protected $utc_offset; |
||
88 | |||
89 | /** |
||
90 | * @var string |
||
91 | */ |
||
92 | protected $time_zone; |
||
93 | |||
94 | /** |
||
95 | * @var bool |
||
96 | */ |
||
97 | protected $geo_enabled; |
||
98 | |||
99 | /** |
||
100 | * @var bool |
||
101 | */ |
||
102 | protected $verified; |
||
103 | |||
104 | /** |
||
105 | * @var int |
||
106 | */ |
||
107 | protected $statuses_count; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | */ |
||
112 | protected $lang; |
||
113 | |||
114 | /** |
||
115 | * @var array |
||
116 | */ |
||
117 | //protected $status; |
||
118 | |||
119 | /** |
||
120 | * @var bool |
||
121 | */ |
||
122 | protected $contributors_enabled; |
||
123 | |||
124 | /** |
||
125 | * @var bool |
||
126 | */ |
||
127 | //protected $is_translator; |
||
128 | |||
129 | /** |
||
130 | * @var bool |
||
131 | */ |
||
132 | //protected $is_translator_enabled; |
||
133 | |||
134 | /** |
||
135 | * @var string |
||
136 | */ |
||
137 | protected $profile_background_color; |
||
138 | |||
139 | /** |
||
140 | * @var string |
||
141 | */ |
||
142 | protected $profile_background_image_url; |
||
143 | |||
144 | /** |
||
145 | * @var string |
||
146 | */ |
||
147 | protected $profile_background_image_url_https; |
||
148 | |||
149 | /** |
||
150 | * @var bool |
||
151 | */ |
||
152 | protected $profile_background_tile; |
||
153 | |||
154 | /** |
||
155 | * @var string |
||
156 | */ |
||
157 | protected $profile_image_url; |
||
158 | |||
159 | /** |
||
160 | * @var string |
||
161 | */ |
||
162 | protected $profile_image_url_https; |
||
163 | |||
164 | /** |
||
165 | * @var string |
||
166 | */ |
||
167 | //protected $profile_banner_url; |
||
168 | |||
169 | /** |
||
170 | * @var string |
||
171 | */ |
||
172 | protected $profile_link_color; |
||
173 | |||
174 | /** |
||
175 | * @var string |
||
176 | */ |
||
177 | protected $profile_sidebar_border_color; |
||
178 | |||
179 | /** |
||
180 | * @var string |
||
181 | */ |
||
182 | protected $profile_sidebar_fill_color; |
||
183 | |||
184 | /** |
||
185 | * @var string |
||
186 | */ |
||
187 | protected $profile_text_color; |
||
188 | |||
189 | /** |
||
190 | * @var bool |
||
191 | */ |
||
192 | protected $profile_use_background_image; |
||
193 | |||
194 | /** |
||
195 | * @var bool |
||
196 | */ |
||
197 | //protected $has_extended_profile; |
||
198 | |||
199 | /** |
||
200 | * @var bool |
||
201 | */ |
||
202 | protected $default_profile; |
||
203 | |||
204 | /** |
||
205 | * @var bool |
||
206 | */ |
||
207 | protected $default_profile_image; |
||
208 | |||
209 | /** |
||
210 | * @var bool |
||
211 | */ |
||
212 | protected $following; |
||
213 | |||
214 | /** |
||
215 | * @var bool |
||
216 | */ |
||
217 | protected $follow_request_sent; |
||
218 | |||
219 | /** |
||
220 | * @var bool |
||
221 | */ |
||
222 | protected $notifications; |
||
223 | |||
224 | /** |
||
225 | * @return int |
||
226 | */ |
||
227 | 4 | public function id(): int |
|
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | 4 | public function idStr(): string |
|
239 | |||
240 | /** |
||
241 | * @return string |
||
242 | */ |
||
243 | 4 | public function name(): string |
|
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | 4 | public function screenName(): string |
|
255 | |||
256 | /** |
||
257 | * @return string |
||
258 | */ |
||
259 | 4 | public function location(): string |
|
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | public function profileLocation(): string |
||
271 | |||
272 | /** |
||
273 | * @return string |
||
274 | */ |
||
275 | 4 | public function description(): string |
|
279 | |||
280 | /** |
||
281 | * @return string |
||
282 | */ |
||
283 | 4 | public function url(): string |
|
287 | |||
288 | /** |
||
289 | * @return bool |
||
290 | */ |
||
291 | 4 | public function protected(): bool |
|
295 | |||
296 | /** |
||
297 | * @return int |
||
298 | */ |
||
299 | 4 | public function followersCount(): int |
|
303 | |||
304 | /** |
||
305 | * @return int |
||
306 | */ |
||
307 | 4 | public function friendsCount(): int |
|
311 | |||
312 | /** |
||
313 | * @return int |
||
314 | */ |
||
315 | 4 | public function listedCount(): int |
|
319 | |||
320 | /** |
||
321 | * @return DateTime |
||
322 | */ |
||
323 | public function createdAt(): DateTime |
||
327 | |||
328 | /** |
||
329 | * @return int |
||
330 | */ |
||
331 | 4 | public function favouritesCount(): int |
|
335 | |||
336 | /** |
||
337 | * @return int |
||
338 | */ |
||
339 | 4 | public function utcOffset(): int |
|
343 | |||
344 | /** |
||
345 | * @return string |
||
346 | */ |
||
347 | 4 | public function timeZone(): string |
|
351 | |||
352 | /** |
||
353 | * @return bool |
||
354 | */ |
||
355 | 4 | public function geoEnabled(): bool |
|
359 | |||
360 | /** |
||
361 | * @return bool |
||
362 | */ |
||
363 | 4 | public function verified(): bool |
|
367 | |||
368 | /** |
||
369 | * @return int |
||
370 | */ |
||
371 | 4 | public function statusesCount(): int |
|
375 | |||
376 | /** |
||
377 | * @return string |
||
378 | */ |
||
379 | 4 | public function lang(): string |
|
383 | |||
384 | /** |
||
385 | * @return array |
||
386 | */ |
||
387 | public function status(): array |
||
391 | |||
392 | /** |
||
393 | * @return bool |
||
394 | */ |
||
395 | 4 | public function contributorsEnabled(): bool |
|
399 | |||
400 | /** |
||
401 | * @return bool |
||
402 | */ |
||
403 | public function isTranslator(): bool |
||
407 | |||
408 | /** |
||
409 | * @return bool |
||
410 | */ |
||
411 | public function isTranslatorEnabled(): bool |
||
415 | |||
416 | /** |
||
417 | * @return string |
||
418 | */ |
||
419 | 4 | public function profileBackgroundColor(): string |
|
423 | |||
424 | /** |
||
425 | * @return string |
||
426 | */ |
||
427 | 4 | public function profileBackgroundImageUrl(): string |
|
431 | |||
432 | /** |
||
433 | * @return string |
||
434 | */ |
||
435 | 4 | public function profileBackgroundImageUrlHttps(): string |
|
439 | |||
440 | /** |
||
441 | * @return bool |
||
442 | */ |
||
443 | 4 | public function profileBackgroundTile(): bool |
|
447 | |||
448 | /** |
||
449 | * @return string |
||
450 | */ |
||
451 | 4 | public function profileImageUrl(): string |
|
455 | |||
456 | /** |
||
457 | * @return string |
||
458 | */ |
||
459 | 4 | public function profileImageUrlHttps(): string |
|
463 | |||
464 | /** |
||
465 | * @return string |
||
466 | */ |
||
467 | public function profileBannerUrl(): string |
||
471 | |||
472 | /** |
||
473 | * @return string |
||
474 | */ |
||
475 | 4 | public function profileLinkColor(): string |
|
479 | |||
480 | /** |
||
481 | * @return string |
||
482 | */ |
||
483 | 4 | public function profileSidebarBorderColor(): string |
|
487 | |||
488 | /** |
||
489 | * @return string |
||
490 | */ |
||
491 | 4 | public function profileSidebarFillColor(): string |
|
495 | |||
496 | /** |
||
497 | * @return string |
||
498 | */ |
||
499 | 4 | public function profileTextColor(): string |
|
503 | |||
504 | /** |
||
505 | * @return bool |
||
506 | */ |
||
507 | 4 | public function profileUseBackgroundImage(): bool |
|
511 | |||
512 | /** |
||
513 | * @return bool |
||
514 | */ |
||
515 | public function hasExtendedProfile(): bool |
||
519 | |||
520 | /** |
||
521 | * @return bool |
||
522 | */ |
||
523 | 4 | public function defaultProfile(): bool |
|
527 | |||
528 | /** |
||
529 | * @return bool |
||
530 | */ |
||
531 | 4 | public function defaultProfileImage(): bool |
|
535 | |||
536 | /** |
||
537 | * @return bool |
||
538 | */ |
||
539 | 4 | public function following(): bool |
|
543 | |||
544 | /** |
||
545 | * @return bool |
||
546 | */ |
||
547 | 4 | public function followRequestSent(): bool |
|
551 | |||
552 | /** |
||
553 | * @return bool |
||
554 | */ |
||
555 | 4 | public function notifications(): bool |
|
559 | } |
||
560 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.