Complex classes like UserEntityTrait 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 UserEntityTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | trait UserEntityTrait |
||
9 | { |
||
10 | protected $id; |
||
11 | protected $status; |
||
12 | protected $isAdmin; |
||
13 | protected $email = null; |
||
14 | protected $pendingEmail = null; |
||
15 | protected $deletedEmail = null; |
||
16 | protected $isEmailConfirmed = false; |
||
17 | protected $emailConfirmationToken; |
||
18 | protected $emailConfirmationTokenExpirationDatetime; |
||
19 | protected $lastEmailTokenGeneratedDatetime; |
||
20 | protected $password; |
||
21 | protected $passwordResetToken; |
||
22 | protected $passwordResetTokenExpirationDatetime; |
||
23 | protected $lastPasswordResetTokenGeneratedDatetime; |
||
24 | protected $creationDatetime; |
||
25 | protected $modificationDatetime; |
||
26 | |||
27 | public function __construct() |
||
33 | |||
34 | public function getId(): int |
||
38 | |||
39 | public function setId(int $id): UserEntityInterface |
||
44 | |||
45 | /** @return string|null */ |
||
46 | public function getStatus() |
||
50 | |||
51 | public function setStatus(string $status): UserEntityInterface |
||
56 | |||
57 | public function isAdmin(): bool |
||
61 | |||
62 | public function setIsAdmin(bool $isAdmin): UserEntityInterface |
||
67 | |||
68 | public function isActive(): bool |
||
72 | |||
73 | public function getEmail(): string |
||
77 | |||
78 | public function setEmail(string $email): UserEntityInterface |
||
83 | |||
84 | /** @return string */ |
||
85 | public function getPendingEmail() |
||
89 | |||
90 | public function setPendingEmail(string $pendingEmail): UserEntityInterface |
||
95 | |||
96 | public function isEmailConfirmed(): bool |
||
100 | |||
101 | public function setIsEmailConfirmed(bool $isEmailConfirmed): UserEntityInterface |
||
106 | |||
107 | /** @return string */ |
||
108 | public function getEmailConfirmationToken() |
||
112 | |||
113 | public function setEmailConfirmationToken(string $emailConfirmationToken): UserEntityInterface |
||
118 | |||
119 | /** @return DateTime */ |
||
120 | public function getEmailConfirmationTokenExpirationDatetime() |
||
124 | |||
125 | public function setEmailConfirmationTokenExpirationDatetime( |
||
131 | |||
132 | /** @return DateTime */ |
||
133 | public function getLastEmailTokenGeneratedDatetime() |
||
137 | |||
138 | public function setLastEmailTokenGeneratedDatetime( |
||
144 | |||
145 | public function canGenerateNewEmailConfirmationToken(): bool |
||
153 | |||
154 | public function generateEmailConfirmationToken(): UserEntityInterface |
||
162 | |||
163 | /** @return string */ |
||
164 | public function getDeletedEmail() |
||
168 | |||
169 | public function setDeletedEmail(string $deletedEmail): UserEntityInterface |
||
174 | |||
175 | public function getPassword(): string |
||
179 | |||
180 | public function setPassword(string $password): UserEntityInterface |
||
186 | |||
187 | /** @return string */ |
||
188 | public function getPasswordResetToken() |
||
192 | |||
193 | public function setPasswordResetToken(string $passwordResetToken): UserEntityInterface |
||
198 | |||
199 | /** @return DateTime */ |
||
200 | public function getPasswordResetTokenExpirationDatetime() |
||
204 | |||
205 | public function setPasswordResetTokenExpirationDatetime( |
||
211 | |||
212 | /** @return DateTime */ |
||
213 | public function getLastPasswordResetTokenGeneratedDatetime() |
||
217 | |||
218 | public function setLastPasswordResetTokenGeneratedDatetime( |
||
224 | |||
225 | public function canGenerateNewResetPasswordToken(): bool |
||
233 | |||
234 | public function generatePasswordResetToken(): UserEntityInterface |
||
242 | |||
243 | protected function hashPassword(): UserEntityInterface |
||
251 | |||
252 | public function testPassword(string $password): bool |
||
256 | |||
257 | public function getCreationDatetime(): DateTime |
||
261 | |||
262 | public function setCreationDatetime(DateTime $creationDatetime): UserEntityInterface |
||
267 | |||
268 | public function getModificationDatetime(): DateTime |
||
272 | |||
273 | public function setModificationDatetime(DateTime $modificationDatetime): UserEntityInterface |
||
278 | |||
279 | public function toArray(): array |
||
290 | |||
291 | public function jsonSerialize() |
||
295 | } |
||
296 |