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 |
||
11 | class User extends BaseUser implements UserInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $locale; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $displayname; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $confirmationType; |
||
27 | |||
28 | /** |
||
29 | * @var \DateTime |
||
30 | */ |
||
31 | protected $confirmedAt; |
||
32 | |||
33 | /** |
||
34 | * @var ArrayCollection|Role[] |
||
35 | */ |
||
36 | protected $authorizationRoles; |
||
37 | |||
38 | /** |
||
39 | * @var ImageInterface |
||
40 | */ |
||
41 | protected $picture; |
||
42 | |||
43 | public function __construct() |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function getAuthorizationRoles() |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function resizeSecurityRoles() |
||
71 | |||
72 | /** |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function isLocked() |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getDisplayName() |
||
95 | |||
96 | /** |
||
97 | * @param null|string $displayname |
||
98 | */ |
||
99 | public function setDisplayName($displayname = null) |
||
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getLocale() |
||
111 | |||
112 | /** |
||
113 | * @param string $locale |
||
114 | */ |
||
115 | public function setLocale($locale) |
||
119 | |||
120 | /** |
||
121 | * @return string|void |
||
122 | */ |
||
123 | public function getLang() |
||
133 | |||
134 | /** |
||
135 | * @inheritdoc |
||
136 | */ |
||
137 | public function getMediaPath() |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function setPicture(ImageInterface $picture = null) |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | public function getPicture() |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function getProfilePicture() |
||
175 | |||
176 | /** |
||
177 | * @inheritdoc |
||
178 | */ |
||
179 | public function getConfirmedAt() |
||
183 | |||
184 | /** |
||
185 | * @inheritdoc |
||
186 | */ |
||
187 | public function setConfirmedAt(\DateTime $confirmedAt = null) |
||
191 | |||
192 | /** |
||
193 | * @inheritdoc |
||
194 | */ |
||
195 | public function confirmed(\DateTime $confirmedAt = null) |
||
202 | |||
203 | /** |
||
204 | * @inheritdoc |
||
205 | */ |
||
206 | public function isConfirmed() |
||
210 | |||
211 | /** |
||
212 | * {@inheritdoc} |
||
213 | */ |
||
214 | public function setEnabled($boolean) |
||
224 | |||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | */ |
||
228 | public function getConfirmationChannel($propertyPath) |
||
234 | |||
235 | /** |
||
236 | * {@inheritdoc} |
||
237 | */ |
||
238 | public function getConfirmationRequestedAt() |
||
242 | |||
243 | /** |
||
244 | * {@inheritdoc} |
||
245 | */ |
||
246 | public function setConfirmationRequestedAt(\DateTime $dateTime = null) |
||
250 | |||
251 | /** |
||
252 | * {@inheritdoc} |
||
253 | */ |
||
254 | public function getConfirmationConfirmedAt() |
||
258 | |||
259 | /** |
||
260 | * {@inheritdoc} |
||
261 | */ |
||
262 | public function setConfirmationConfirmedAt(\DateTime $dateTime = null) |
||
266 | |||
267 | /** |
||
268 | * {@inheritdoc} |
||
269 | */ |
||
270 | public function isConfirmationConfirmed() |
||
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function confirmationRequest($token) |
||
284 | |||
285 | /** |
||
286 | * {@inheritdoc} |
||
287 | */ |
||
288 | public function confirmationConfirm() |
||
292 | |||
293 | /** |
||
294 | * {@inheritdoc} |
||
295 | */ |
||
296 | public function getConfirmationType() |
||
300 | |||
301 | /** |
||
302 | * {@inheritdoc} |
||
303 | */ |
||
304 | public function setConfirmationType($confirmationType) |
||
308 | |||
309 | /** |
||
310 | * {@inheritdoc} |
||
311 | */ |
||
312 | public function confirmationDisableAccess() |
||
316 | |||
317 | /** |
||
318 | * {@inheritdoc} |
||
319 | */ |
||
320 | public function confirmationEnableAccess() |
||
324 | } |
||
325 |