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 |
||
12 | class User extends BaseUser implements UserInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $locale; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $displayname; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $confirmationType; |
||
28 | |||
29 | /** |
||
30 | * @var \DateTime |
||
31 | */ |
||
32 | protected $confirmedAt; |
||
33 | |||
34 | /** |
||
35 | * @var ArrayCollection|Role[] |
||
36 | */ |
||
37 | protected $authorizationRoles; |
||
38 | |||
39 | /** |
||
40 | * @var ImageInterface |
||
41 | */ |
||
42 | protected $picture; |
||
43 | |||
44 | public function __construct() |
||
50 | |||
51 | /** |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function isLocked() |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getDisplayName() |
||
74 | |||
75 | /** |
||
76 | * @param null|string $displayname |
||
77 | */ |
||
78 | public function setDisplayName($displayname = null) |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getLocale() |
||
90 | |||
91 | /** |
||
92 | * @param string $locale |
||
93 | */ |
||
94 | public function setLocale($locale) |
||
98 | |||
99 | /** |
||
100 | * @return string|void |
||
101 | */ |
||
102 | public function getLang() |
||
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | public function getMediaPath() |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function setPicture(ImageInterface $picture = null) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getPicture() |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function getProfilePicture() |
||
154 | |||
155 | /** |
||
156 | * @inheritdoc |
||
157 | */ |
||
158 | public function getConfirmedAt() |
||
162 | |||
163 | /** |
||
164 | * @inheritdoc |
||
165 | */ |
||
166 | public function setConfirmedAt(\DateTime $confirmedAt = null) |
||
170 | |||
171 | /** |
||
172 | * @inheritdoc |
||
173 | */ |
||
174 | public function confirmed(\DateTime $confirmedAt = null) |
||
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | */ |
||
185 | public function isConfirmed() |
||
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | public function setEnabled($boolean) |
||
203 | |||
204 | /** |
||
205 | * {@inheritdoc} |
||
206 | */ |
||
207 | public function getConfirmationChannel($propertyPath) |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function getConfirmationRequestedAt() |
||
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | public function setConfirmationRequestedAt(\DateTime $dateTime = null) |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | public function getConfirmationConfirmedAt() |
||
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | public function setConfirmationConfirmedAt(\DateTime $dateTime = null) |
||
245 | |||
246 | /** |
||
247 | * {@inheritdoc} |
||
248 | */ |
||
249 | public function isConfirmationConfirmed() |
||
253 | |||
254 | /** |
||
255 | * {@inheritdoc} |
||
256 | */ |
||
257 | public function confirmationRequest($token) |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | */ |
||
267 | public function confirmationConfirm() |
||
271 | |||
272 | /** |
||
273 | * {@inheritdoc} |
||
274 | */ |
||
275 | public function getConfirmationType() |
||
279 | |||
280 | /** |
||
281 | * {@inheritdoc} |
||
282 | */ |
||
283 | public function setConfirmationType($confirmationType) |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | public function confirmationDisableAccess() |
||
295 | |||
296 | /** |
||
297 | * {@inheritdoc} |
||
298 | */ |
||
299 | public function confirmationEnableAccess() |
||
303 | |||
304 | /** |
||
305 | * {@inheritdoc} |
||
306 | */ |
||
307 | public function getAuthorizationRoles() |
||
311 | |||
312 | /** |
||
313 | * {@inheritdoc} |
||
314 | */ |
||
315 | public function addAuthorizationRole(RoleInterface $role) |
||
321 | |||
322 | /** |
||
323 | * {@inheritdoc} |
||
324 | */ |
||
325 | public function removeAuthorizationRole(RoleInterface $role) |
||
331 | |||
332 | /** |
||
333 | * {@inheritdoc} |
||
334 | */ |
||
335 | public function hasAuthorizationRole(RoleInterface $role) |
||
339 | |||
340 | /** |
||
341 | * {@inheritdoc} |
||
342 | */ |
||
343 | public function getRoles() |
||
353 | } |
||
354 |