Total Complexity | 45 |
Total Lines | 572 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like SimpleUserTransfer 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.
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 SimpleUserTransfer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | final class SimpleUserTransfer extends \Micro\Library\DTO\Object\AbstractDto |
||
14 | { |
||
15 | protected SimpleObjectTransfer|null $parent = null; |
||
16 | |||
17 | #[\Symfony\Component\Validator\Constraints\Length(groups: ['Default'], max: 50, min: 6)] |
||
18 | #[\Symfony\Component\Validator\Constraints\Regex(groups: ['Default'], pattern: '/^(.[aA-zA]+)$/', match: true)] |
||
19 | protected string|null $username = null; |
||
20 | |||
21 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
22 | #[\Symfony\Component\Validator\Constraints\GreaterThan(groups: ['Default'], value: 18)] |
||
23 | #[\Symfony\Component\Validator\Constraints\LessThan(groups: ['Default'], value: 100)] |
||
24 | protected int|null $age = null; |
||
25 | |||
26 | #[\Symfony\Component\Validator\Constraints\Email(groups: ['Default'], mode: 'html5')] |
||
27 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
28 | protected string|null $email = null; |
||
29 | |||
30 | #[\Symfony\Component\Validator\Constraints\Ip(groups: ['Default'], version: '4')] |
||
31 | protected string|null $ip = null; |
||
32 | |||
33 | #[\Symfony\Component\Validator\Constraints\Hostname(groups: ['Default'], requireTld: false)] |
||
34 | protected string|null $hostname = null; |
||
35 | |||
36 | #[\Symfony\Component\Validator\Constraints\Regex(groups: ['Default'], pattern: '/^(.[a-z])+$/', match: true)] |
||
37 | protected string|null $sometext = null; |
||
38 | |||
39 | #[\Symfony\Component\Validator\Constraints\Url(groups: ['Default'], relativeProtocol: true)] |
||
40 | protected string|null $url = null; |
||
41 | |||
42 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
43 | #[\Symfony\Component\Validator\Constraints\Json(groups: ['Default'])] |
||
44 | protected string|null $json = null; |
||
45 | |||
46 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
47 | #[\Symfony\Component\Validator\Constraints\Uuid(groups: ['Default'], versions: [1, 2, 3, 4, 5, 6], strict: true)] |
||
48 | protected string|null $uuid = null; |
||
49 | |||
50 | #[\Symfony\Component\Validator\Constraints\DateTime(groups: ['Default'], format: 'Y-m-d H:i:s')] |
||
51 | protected string|null $created_at = null; |
||
52 | |||
53 | #[\Symfony\Component\Validator\Constraints\Date(groups: ['Default'])] |
||
54 | protected string|null $updated_at = null; |
||
55 | |||
56 | #[\Symfony\Component\Validator\Constraints\Timezone(groups: ['Default'], countryCode: 'BY', intlCompatible: true, zone: 4096)] |
||
57 | protected string|null $timezone = null; |
||
58 | |||
59 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
60 | #[\Symfony\Component\Validator\Constraints\CardScheme(groups: ['Default'], schemes: ['MASTERCARD'])] |
||
61 | #[\Symfony\Component\Validator\Constraints\Luhn(groups: ['Default'])] |
||
62 | protected string|null $card_scheme = null; |
||
63 | |||
64 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
65 | #[\Symfony\Component\Validator\Constraints\Bic(groups: ['Default'])] |
||
66 | protected string|null $bic = null; |
||
67 | |||
68 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
69 | #[\Symfony\Component\Validator\Constraints\Currency(groups: ['Default'])] |
||
70 | protected string|null $currency = null; |
||
71 | |||
72 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
73 | #[\Symfony\Component\Validator\Constraints\Iban(groups: ['Default'])] |
||
74 | protected string|null $iban = null; |
||
75 | |||
76 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
77 | #[\Symfony\Component\Validator\Constraints\Isbn(groups: ['Default'], type: 'isbn13')] |
||
78 | protected string|null $isbn = null; |
||
79 | |||
80 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
81 | #[\Symfony\Component\Validator\Constraints\Issn(groups: ['Default'])] |
||
82 | protected string|null $issn = null; |
||
83 | |||
84 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
85 | #[\Symfony\Component\Validator\Constraints\Isin(groups: ['Default'])] |
||
86 | protected string|null $isin = null; |
||
87 | |||
88 | #[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)] |
||
89 | #[\Symfony\Component\Validator\Constraints\Choice(groups: ['Default'], choices: [1, 'example', 0.001, true])] |
||
90 | protected string|int|float|array|null $choice = null; |
||
91 | |||
92 | #[\Symfony\Component\Validator\Constraints\Expression(groups: ['Default'], expression: 'this.getChoice() === excepted', values: ['excepted' => 'example'])] |
||
93 | protected string|int|null $expression = null; |
||
94 | |||
95 | public function getParent(): SimpleObjectTransfer|null |
||
96 | { |
||
97 | return $this->parent; |
||
98 | } |
||
99 | |||
100 | public function getUsername(): string|null |
||
101 | { |
||
102 | return $this->username; |
||
103 | } |
||
104 | |||
105 | public function getAge(): int|null |
||
106 | { |
||
107 | return $this->age; |
||
108 | } |
||
109 | |||
110 | public function getEmail(): string|null |
||
111 | { |
||
112 | return $this->email; |
||
113 | } |
||
114 | |||
115 | public function getIp(): string|null |
||
116 | { |
||
117 | return $this->ip; |
||
118 | } |
||
119 | |||
120 | public function getHostname(): string|null |
||
121 | { |
||
122 | return $this->hostname; |
||
123 | } |
||
124 | |||
125 | public function getSometext(): string|null |
||
126 | { |
||
127 | return $this->sometext; |
||
128 | } |
||
129 | |||
130 | public function getUrl(): string|null |
||
131 | { |
||
132 | return $this->url; |
||
133 | } |
||
134 | |||
135 | public function getJson(): string|null |
||
136 | { |
||
137 | return $this->json; |
||
138 | } |
||
139 | |||
140 | public function getUuid(): string|null |
||
141 | { |
||
142 | return $this->uuid; |
||
143 | } |
||
144 | |||
145 | public function getCreatedAt(): string|null |
||
146 | { |
||
147 | return $this->created_at; |
||
148 | } |
||
149 | |||
150 | public function getUpdatedAt(): string|null |
||
151 | { |
||
152 | return $this->updated_at; |
||
153 | } |
||
154 | |||
155 | public function getTimezone(): string|null |
||
156 | { |
||
157 | return $this->timezone; |
||
158 | } |
||
159 | |||
160 | public function getCardScheme(): string|null |
||
161 | { |
||
162 | return $this->card_scheme; |
||
163 | } |
||
164 | |||
165 | public function getBic(): string|null |
||
166 | { |
||
167 | return $this->bic; |
||
168 | } |
||
169 | |||
170 | public function getCurrency(): string|null |
||
171 | { |
||
172 | return $this->currency; |
||
173 | } |
||
174 | |||
175 | public function getIban(): string|null |
||
176 | { |
||
177 | return $this->iban; |
||
178 | } |
||
179 | |||
180 | public function getIsbn(): string|null |
||
181 | { |
||
182 | return $this->isbn; |
||
183 | } |
||
184 | |||
185 | public function getIssn(): string|null |
||
186 | { |
||
187 | return $this->issn; |
||
188 | } |
||
189 | |||
190 | public function getIsin(): string|null |
||
191 | { |
||
192 | return $this->isin; |
||
193 | } |
||
194 | |||
195 | public function getChoice(): string|int|float|array|null |
||
196 | { |
||
197 | return $this->choice; |
||
198 | } |
||
199 | |||
200 | public function getExpression(): string|int|null |
||
201 | { |
||
202 | return $this->expression; |
||
203 | } |
||
204 | |||
205 | public function setParent(SimpleObjectTransfer|null $parent): self |
||
206 | { |
||
207 | $this->parent = $parent; |
||
208 | |||
209 | return $this; |
||
210 | } |
||
211 | |||
212 | public function setUsername(string|null $username): self |
||
213 | { |
||
214 | $this->username = $username; |
||
215 | |||
216 | return $this; |
||
217 | } |
||
218 | |||
219 | public function setAge(int|null $age): self |
||
220 | { |
||
221 | $this->age = $age; |
||
222 | |||
223 | return $this; |
||
224 | } |
||
225 | |||
226 | public function setEmail(string|null $email): self |
||
227 | { |
||
228 | $this->email = $email; |
||
229 | |||
230 | return $this; |
||
231 | } |
||
232 | |||
233 | public function setIp(string|null $ip): self |
||
234 | { |
||
235 | $this->ip = $ip; |
||
236 | |||
237 | return $this; |
||
238 | } |
||
239 | |||
240 | public function setHostname(string|null $hostname): self |
||
241 | { |
||
242 | $this->hostname = $hostname; |
||
243 | |||
244 | return $this; |
||
245 | } |
||
246 | |||
247 | public function setSometext(string|null $sometext): self |
||
248 | { |
||
249 | $this->sometext = $sometext; |
||
250 | |||
251 | return $this; |
||
252 | } |
||
253 | |||
254 | public function setUrl(string|null $url): self |
||
255 | { |
||
256 | $this->url = $url; |
||
257 | |||
258 | return $this; |
||
259 | } |
||
260 | |||
261 | public function setJson(string|null $json): self |
||
262 | { |
||
263 | $this->json = $json; |
||
264 | |||
265 | return $this; |
||
266 | } |
||
267 | |||
268 | public function setUuid(string|null $uuid): self |
||
269 | { |
||
270 | $this->uuid = $uuid; |
||
271 | |||
272 | return $this; |
||
273 | } |
||
274 | |||
275 | public function setCreatedAt(string|null $created_at): self |
||
276 | { |
||
277 | $this->created_at = $created_at; |
||
278 | |||
279 | return $this; |
||
280 | } |
||
281 | |||
282 | public function setUpdatedAt(string|null $updated_at): self |
||
283 | { |
||
284 | $this->updated_at = $updated_at; |
||
285 | |||
286 | return $this; |
||
287 | } |
||
288 | |||
289 | public function setTimezone(string|null $timezone): self |
||
290 | { |
||
291 | $this->timezone = $timezone; |
||
292 | |||
293 | return $this; |
||
294 | } |
||
295 | |||
296 | public function setCardScheme(string|null $card_scheme): self |
||
297 | { |
||
298 | $this->card_scheme = $card_scheme; |
||
299 | |||
300 | return $this; |
||
301 | } |
||
302 | |||
303 | public function setBic(string|null $bic): self |
||
304 | { |
||
305 | $this->bic = $bic; |
||
306 | |||
307 | return $this; |
||
308 | } |
||
309 | |||
310 | public function setCurrency(string|null $currency): self |
||
311 | { |
||
312 | $this->currency = $currency; |
||
313 | |||
314 | return $this; |
||
315 | } |
||
316 | |||
317 | public function setIban(string|null $iban): self |
||
318 | { |
||
319 | $this->iban = $iban; |
||
320 | |||
321 | return $this; |
||
322 | } |
||
323 | |||
324 | public function setIsbn(string|null $isbn): self |
||
325 | { |
||
326 | $this->isbn = $isbn; |
||
327 | |||
328 | return $this; |
||
329 | } |
||
330 | |||
331 | public function setIssn(string|null $issn): self |
||
332 | { |
||
333 | $this->issn = $issn; |
||
334 | |||
335 | return $this; |
||
336 | } |
||
337 | |||
338 | public function setIsin(string|null $isin): self |
||
339 | { |
||
340 | $this->isin = $isin; |
||
341 | |||
342 | return $this; |
||
343 | } |
||
344 | |||
345 | public function setChoice(string|int|float|array|null $choice): self |
||
346 | { |
||
347 | $this->choice = $choice; |
||
348 | |||
349 | return $this; |
||
350 | } |
||
351 | |||
352 | public function setExpression(string|int|null $expression): self |
||
353 | { |
||
354 | $this->expression = $expression; |
||
355 | |||
356 | return $this; |
||
357 | } |
||
358 | |||
359 | protected static function attributesMetadata(): array |
||
360 | { |
||
361 | return array ( |
||
362 | 'parent' => |
||
363 | array ( |
||
364 | 'type' => |
||
365 | array ( |
||
366 | 0 => 'Transfer\\Simple\\SimpleObjectTransfer', |
||
367 | 1 => 'null', |
||
368 | ), |
||
369 | 'required' => false, |
||
370 | 'actionName' => 'parent', |
||
371 | ), |
||
372 | 'username' => |
||
373 | array ( |
||
374 | 'type' => |
||
375 | array ( |
||
376 | 0 => 'string', |
||
377 | 1 => 'null', |
||
378 | ), |
||
379 | 'required' => false, |
||
380 | 'actionName' => 'username', |
||
381 | ), |
||
382 | 'age' => |
||
383 | array ( |
||
384 | 'type' => |
||
385 | array ( |
||
386 | 0 => 'int', |
||
387 | 1 => 'null', |
||
388 | ), |
||
389 | 'required' => false, |
||
390 | 'actionName' => 'age', |
||
391 | ), |
||
392 | 'email' => |
||
393 | array ( |
||
394 | 'type' => |
||
395 | array ( |
||
396 | 0 => 'string', |
||
397 | 1 => 'null', |
||
398 | ), |
||
399 | 'required' => false, |
||
400 | 'actionName' => 'email', |
||
401 | ), |
||
402 | 'ip' => |
||
403 | array ( |
||
404 | 'type' => |
||
405 | array ( |
||
406 | 0 => 'string', |
||
407 | 1 => 'null', |
||
408 | ), |
||
409 | 'required' => false, |
||
410 | 'actionName' => 'ip', |
||
411 | ), |
||
412 | 'hostname' => |
||
413 | array ( |
||
414 | 'type' => |
||
415 | array ( |
||
416 | 0 => 'string', |
||
417 | 1 => 'null', |
||
418 | ), |
||
419 | 'required' => false, |
||
420 | 'actionName' => 'hostname', |
||
421 | ), |
||
422 | 'sometext' => |
||
423 | array ( |
||
424 | 'type' => |
||
425 | array ( |
||
426 | 0 => 'string', |
||
427 | 1 => 'null', |
||
428 | ), |
||
429 | 'required' => false, |
||
430 | 'actionName' => 'sometext', |
||
431 | ), |
||
432 | 'url' => |
||
433 | array ( |
||
434 | 'type' => |
||
435 | array ( |
||
436 | 0 => 'string', |
||
437 | 1 => 'null', |
||
438 | ), |
||
439 | 'required' => false, |
||
440 | 'actionName' => 'url', |
||
441 | ), |
||
442 | 'json' => |
||
443 | array ( |
||
444 | 'type' => |
||
445 | array ( |
||
446 | 0 => 'string', |
||
447 | 1 => 'null', |
||
448 | ), |
||
449 | 'required' => false, |
||
450 | 'actionName' => 'json', |
||
451 | ), |
||
452 | 'uuid' => |
||
453 | array ( |
||
454 | 'type' => |
||
455 | array ( |
||
456 | 0 => 'string', |
||
457 | 1 => 'null', |
||
458 | ), |
||
459 | 'required' => false, |
||
460 | 'actionName' => 'uuid', |
||
461 | ), |
||
462 | 'created_at' => |
||
463 | array ( |
||
464 | 'type' => |
||
465 | array ( |
||
466 | 0 => 'string', |
||
467 | 1 => 'null', |
||
468 | ), |
||
469 | 'required' => false, |
||
470 | 'actionName' => 'createdAt', |
||
471 | ), |
||
472 | 'updated_at' => |
||
473 | array ( |
||
474 | 'type' => |
||
475 | array ( |
||
476 | 0 => 'string', |
||
477 | 1 => 'null', |
||
478 | ), |
||
479 | 'required' => false, |
||
480 | 'actionName' => 'updatedAt', |
||
481 | ), |
||
482 | 'timezone' => |
||
483 | array ( |
||
484 | 'type' => |
||
485 | array ( |
||
486 | 0 => 'string', |
||
487 | 1 => 'null', |
||
488 | ), |
||
489 | 'required' => false, |
||
490 | 'actionName' => 'timezone', |
||
491 | ), |
||
492 | 'card_scheme' => |
||
493 | array ( |
||
494 | 'type' => |
||
495 | array ( |
||
496 | 0 => 'string', |
||
497 | 1 => 'null', |
||
498 | ), |
||
499 | 'required' => false, |
||
500 | 'actionName' => 'cardScheme', |
||
501 | ), |
||
502 | 'bic' => |
||
503 | array ( |
||
504 | 'type' => |
||
505 | array ( |
||
506 | 0 => 'string', |
||
507 | 1 => 'null', |
||
508 | ), |
||
509 | 'required' => false, |
||
510 | 'actionName' => 'bic', |
||
511 | ), |
||
512 | 'currency' => |
||
513 | array ( |
||
514 | 'type' => |
||
515 | array ( |
||
516 | 0 => 'string', |
||
517 | 1 => 'null', |
||
518 | ), |
||
519 | 'required' => false, |
||
520 | 'actionName' => 'currency', |
||
521 | ), |
||
522 | 'iban' => |
||
523 | array ( |
||
524 | 'type' => |
||
525 | array ( |
||
526 | 0 => 'string', |
||
527 | 1 => 'null', |
||
528 | ), |
||
529 | 'required' => false, |
||
530 | 'actionName' => 'iban', |
||
531 | ), |
||
532 | 'isbn' => |
||
533 | array ( |
||
534 | 'type' => |
||
535 | array ( |
||
536 | 0 => 'string', |
||
537 | 1 => 'null', |
||
538 | ), |
||
539 | 'required' => false, |
||
540 | 'actionName' => 'isbn', |
||
541 | ), |
||
542 | 'issn' => |
||
543 | array ( |
||
544 | 'type' => |
||
545 | array ( |
||
546 | 0 => 'string', |
||
547 | 1 => 'null', |
||
548 | ), |
||
549 | 'required' => false, |
||
550 | 'actionName' => 'issn', |
||
551 | ), |
||
552 | 'isin' => |
||
553 | array ( |
||
554 | 'type' => |
||
555 | array ( |
||
556 | 0 => 'string', |
||
557 | 1 => 'null', |
||
558 | ), |
||
559 | 'required' => false, |
||
560 | 'actionName' => 'isin', |
||
561 | ), |
||
562 | 'choice' => |
||
563 | array ( |
||
564 | 'type' => |
||
565 | array ( |
||
566 | 0 => 'string', |
||
567 | 1 => 'int', |
||
568 | 2 => 'float', |
||
569 | 3 => 'array', |
||
570 | 4 => 'null', |
||
571 | ), |
||
572 | 'required' => false, |
||
573 | 'actionName' => 'choice', |
||
574 | ), |
||
575 | 'expression' => |
||
576 | array ( |
||
577 | 'type' => |
||
578 | array ( |
||
579 | 0 => 'string', |
||
580 | 1 => 'int', |
||
581 | 2 => 'null', |
||
582 | ), |
||
583 | 'required' => false, |
||
584 | 'actionName' => 'expression', |
||
585 | ), |
||
589 |