Completed
Pull Request — master (#105)
by Tom
02:40
created

VCard   B

Complexity

Total Complexity 46

Size/Duplication

Total Lines 585
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Importance

Changes 0
Metric Value
wmc 46
lcom 4
cbo 0
dl 0
loc 585
rs 8.3999
c 0
b 0
f 0

46 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullName() 0 4 1
A setFullName() 0 4 1
A getLastName() 0 4 1
A setLastName() 0 4 1
A getFirstName() 0 4 1
A setFirstName() 0 4 1
A getAdditional() 0 4 1
A setAdditional() 0 4 1
A getPrefix() 0 4 1
A setPrefix() 0 4 1
A getSuffix() 0 4 1
A setSuffix() 0 4 1
A getBirthday() 0 4 1
A setBirthday() 0 4 1
A getAddresses() 0 4 1
A setAddresses() 0 4 1
A getAddress() 0 4 1
A addAddress() 0 4 1
A getPhones() 0 4 1
A setPhones() 0 4 1
A getPhone() 0 4 1
A addPhone() 0 4 1
A getEmails() 0 4 1
A setEmails() 0 4 1
A getEmail() 0 4 1
A addEmail() 0 4 1
A getRevision() 0 4 1
A setRevision() 0 4 1
A getVersion() 0 4 1
A setVersion() 0 4 1
A getOrganization() 0 4 1
A setOrganization() 0 4 1
A getUrls() 0 4 1
A setUrls() 0 4 1
A getUrl() 0 4 1
A addUrl() 0 4 1
A getTitle() 0 4 1
A setTitle() 0 4 1
A getPhoto() 0 4 1
A setPhoto() 0 4 1
A getLogo() 0 4 1
A setLogo() 0 4 1
A getNote() 0 4 1
A setNote() 0 4 1
A getCategories() 0 4 1
A setCategories() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like VCard 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 VCard, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace JeroenDesloovere\VCard\Model;
4
5
/**
6
 * Class VCard
7
 *
8
 * @package JeroenDesloovere\VCard\Model
9
 */
10
class VCard extends \stdClass
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $fullName;
16
17
    /**
18
     * @var string|null
19
     */
20
    protected $lastName;
21
22
    /**
23
     * @var string|null
24
     */
25
    protected $firstName;
26
27
    /**
28
     * @var string|null
29
     */
30
    protected $additional;
31
32
    /**
33
     * @var string|null
34
     */
35
    protected $prefix;
36
37
    /**
38
     * @var string|null
39
     */
40
    protected $suffix;
41
42
    /**
43
     * @var \DateTime|null
44
     */
45
    protected $birthday;
46
47
    /**
48
     * @var VCardAddress[][]|null
49
     */
50
    protected $address;
51
52
    /**
53
     * @var string[][]|null
54
     */
55
    protected $phone;
56
57
    /**
58
     * @var string[][]|null
59
     */
60
    protected $email;
61
62
    /**
63
     * @var string|null
64
     */
65
    protected $revision;
66
67
    /**
68
     * @var string|null
69
     */
70
    protected $version;
71
72
    /**
73
     * @var string|null
74
     */
75
    protected $organization;
76
77
    /**
78
     * @var string[][]|null
79
     */
80
    protected $url;
81
82
    /**
83
     * @var string|null
84
     */
85
    protected $title;
86
87
    /**
88
     * @var VCardMedia|null
89
     */
90
    protected $photo;
91
92
    /**
93
     * @var VCardMedia|null
94
     */
95
    protected $logo;
96
97
    /**
98
     * @var string|null
99
     */
100
    protected $note;
101
102
    /**
103
     * @var array|null
104
     */
105
    protected $categories;
106
107
    /**
108
     * @var string|null
109
     */
110
    protected $geo;
111
112
    /**
113
     * @var string|null
114
     */
115
    protected $gender;
116
117
    /**
118
     * @var string[][]|null
119
     */
120
    protected $nickname;
121
122
    /**
123
     * @var string[][]|null
124
     */
125
    protected $skype;
126
127
    /**
128
     * @var array|null
129
     */
130
    protected $item;
131
132
    /**
133
     * @return string
134
     */
135
    public function getFullName(): string
136
    {
137
        return $this->fullName;
138
    }
139
140
    /**
141
     * @param string $fullName
142
     */
143
    public function setFullName(string $fullName): void
144
    {
145
        $this->fullName = $fullName;
146
    }
147
148
    /**
149
     * @return null|string
150
     */
151
    public function getLastName(): ?string
152
    {
153
        return $this->lastName;
154
    }
155
156
    /**
157
     * @param null|string $lastName
158
     */
159
    public function setLastName(?string $lastName): void
160
    {
161
        $this->lastName = $lastName;
162
    }
163
164
    /**
165
     * @return null|string
166
     */
167
    public function getFirstName(): ?string
168
    {
169
        return $this->firstName;
170
    }
171
172
    /**
173
     * @param null|string $firstName
174
     */
175
    public function setFirstName(?string $firstName): void
176
    {
177
        $this->firstName = $firstName;
178
    }
179
180
    /**
181
     * @return null|string
182
     */
183
    public function getAdditional(): ?string
184
    {
185
        return $this->additional;
186
    }
187
188
    /**
189
     * @param null|string $additional
190
     */
191
    public function setAdditional(?string $additional): void
192
    {
193
        $this->additional = $additional;
194
    }
195
196
    /**
197
     * @return null|string
198
     */
199
    public function getPrefix(): ?string
200
    {
201
        return $this->prefix;
202
    }
203
204
    /**
205
     * @param null|string $prefix
206
     */
207
    public function setPrefix(?string $prefix): void
208
    {
209
        $this->prefix = $prefix;
210
    }
211
212
    /**
213
     * @return null|string
214
     */
215
    public function getSuffix(): ?string
216
    {
217
        return $this->suffix;
218
    }
219
220
    /**
221
     * @param null|string $suffix
222
     */
223
    public function setSuffix(?string $suffix): void
224
    {
225
        $this->suffix = $suffix;
226
    }
227
228
    /**
229
     * @return \DateTime|null
230
     */
231
    public function getBirthday(): ?\DateTime
232
    {
233
        return $this->birthday;
234
    }
235
236
    /**
237
     * @param \DateTime|null $birthday
238
     */
239
    public function setBirthday(?\DateTime $birthday): void
240
    {
241
        $this->birthday = $birthday;
242
    }
243
244
    /**
245
     * @return VCardAddress[][]|null
246
     */
247
    public function getAddresses(): ?array
248
    {
249
        return $this->address;
250
    }
251
252
    /**
253
     * @param VCardAddress[][]|null $address
254
     */
255
    public function setAddresses(?array $address): void
256
    {
257
        $this->address = $address;
258
    }
259
260
    /**
261
     * @param string $key
262
     *
263
     * @return VCardAddress[]|null
264
     */
265
    public function getAddress(string $key): ?array
266
    {
267
        return $this->address[$key];
268
    }
269
270
    /**
271
     * @param VCardAddress $address
272
     * @param string       $key
273
     */
274
    public function addAddress(VCardAddress $address, string $key = ''): void
275
    {
276
        $this->address[$key][] = $address;
277
    }
278
279
    /**
280
     * @return null|string[][]
281
     */
282
    public function getPhones(): ?array
283
    {
284
        return $this->phone;
285
    }
286
287
    /**
288
     * @param null|string[][] $phone
289
     */
290
    public function setPhones(?array $phone): void
291
    {
292
        $this->phone = $phone;
293
    }
294
295
    /**
296
     * @param string $key
297
     *
298
     * @return string[]|null
299
     */
300
    public function getPhone(string $key): ?array
301
    {
302
        return $this->phone[$key];
303
    }
304
305
    /**
306
     * @param string $phone
307
     * @param string $key
308
     */
309
    public function addPhone(string $phone, string $key = ''): void
310
    {
311
        $this->phone[$key][] = $phone;
312
    }
313
314
    /**
315
     * @return null|string[][]
316
     */
317
    public function getEmails(): ?array
318
    {
319
        return $this->email;
320
    }
321
322
    /**
323
     * @param null|string[][] $email
324
     */
325
    public function setEmails(?array $email): void
326
    {
327
        $this->email = $email;
328
    }
329
330
    /**
331
     * @param string $key
332
     *
333
     * @return string[]|null
334
     */
335
    public function getEmail(string $key): ?array
336
    {
337
        return $this->email[$key];
338
    }
339
340
    /**
341
     * @param string $email
342
     * @param string $key
343
     */
344
    public function addEmail(string $email, string $key = ''): void
345
    {
346
        $this->email[$key][] = $email;
347
    }
348
349
    /**
350
     * @return null|string
351
     */
352
    public function getRevision(): ?string
353
    {
354
        return $this->revision;
355
    }
356
357
    /**
358
     * @param null|string $revision
359
     */
360
    public function setRevision(?string $revision): void
361
    {
362
        $this->revision = $revision;
363
    }
364
365
    /**
366
     * @return null|string
367
     */
368
    public function getVersion(): ?string
369
    {
370
        return $this->version;
371
    }
372
373
    /**
374
     * @param null|string $version
375
     */
376
    public function setVersion(?string $version): void
377
    {
378
        $this->version = $version;
379
    }
380
381
    /**
382
     * @return null|string
383
     */
384
    public function getOrganization(): ?string
385
    {
386
        return $this->organization;
387
    }
388
389
    /**
390
     * @param null|string $organization
391
     */
392
    public function setOrganization(?string $organization): void
393
    {
394
        $this->organization = $organization;
395
    }
396
397
    /**
398
     * @return null|string[][]
399
     */
400
    public function getUrls(): ?array
401
    {
402
        return $this->url;
403
    }
404
405
    /**
406
     * @param null|string[][] $url
407
     */
408
    public function setUrls(?array $url): void
409
    {
410
        $this->url = $url;
411
    }
412
413
    /**
414
     * @param string $key
415
     *
416
     * @return string[]|null
417
     */
418
    public function getUrl(string $key): ?array
419
    {
420
        return $this->url[$key];
421
    }
422
423
    /**
424
     * @param string $url
425
     * @param string $key
426
     */
427
    public function addUrl(string $url, string $key = ''): void
428
    {
429
        $this->url[$key][] = $url;
430
    }
431
432
    /**
433
     * @return null|string
434
     */
435
    public function getTitle(): ?string
436
    {
437
        return $this->title;
438
    }
439
440
    /**
441
     * @param null|string $title
442
     */
443
    public function setTitle(?string $title): void
444
    {
445
        $this->title = $title;
446
    }
447
448
    /**
449
     * @return null|VCardMedia
450
     */
451
    public function getPhoto(): ?VCardMedia
452
    {
453
        return $this->photo;
454
    }
455
456
    /**
457
     * @param null|VCardMedia $photo
458
     */
459
    public function setPhoto(?VCardMedia $photo): void
460
    {
461
        $this->photo = $photo;
462
    }
463
464
    /**
465
     * @return null|VCardMedia
466
     */
467
    public function getLogo(): ?VCardMedia
468
    {
469
        return $this->logo;
470
    }
471
472
    /**
473
     * @param null|VCardMedia $logo
474
     */
475
    public function setLogo(?VCardMedia $logo): void
476
    {
477
        $this->logo = $logo;
478
    }
479
480
    /**
481
     * @return null|string
482
     */
483
    public function getNote(): ?string
484
    {
485
        return $this->note;
486
    }
487
488
    /**
489
     * @param null|string $note
490
     */
491
    public function setNote(?string $note): void
492
    {
493
        $this->note = $note;
494
    }
495
496
    /**
497
     * @return array|null
498
     */
499
    public function getCategories(): ?array
500
    {
501
        return $this->categories;
502
    }
503
504
    /**
505
     * @param array|null $categories
506
     */
507
    public function setCategories(?array $categories): void
508
    {
509
        $this->categories = $categories;
510
    }
511
512
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
513
//     * TODO: Add functions
514
//     */
515
//    /**
516
//     * @return null|string
517
//     */
518
//    public function getGeo(): ?string
519
//    {
520
//        return $this->geo;
521
//    }
522
//
523
//    /**
524
//     * @param null|string $geo
525
//     */
526
//    public function setGeo(?string $geo): void
527
//    {
528
//        $this->geo = $geo;
529
//    }
530
//
531
//    /**
532
//     * @return null|string
533
//     */
534
//    public function getGender(): ?string
535
//    {
536
//        return $this->gender;
537
//    }
538
//
539
//    /**
540
//     * @param null|string $gender
541
//     */
542
//    public function setGender(?string $gender): void
543
//    {
544
//        $this->gender = $gender;
545
//    }
546
//
547
//    /**
548
//     * @return null|string[][]
549
//     */
550
//    public function getNickname(): ?array
551
//    {
552
//        return $this->nickname;
553
//    }
554
//
555
//    /**
556
//     * @param null|string[][] $nickname
557
//     */
558
//    public function setNickname(?array $nickname): void
559
//    {
560
//        $this->nickname = $nickname;
561
//    }
562
//
563
//    /**
564
//     * @return null|string[][]
565
//     */
566
//    public function getSkype(): ?array
567
//    {
568
//        return $this->skype;
569
//    }
570
//
571
//    /**
572
//     * @param null|string[][] $skype
573
//     */
574
//    public function setSkype(?array $skype): void
575
//    {
576
//        $this->skype = $skype;
577
//    }
578
//
579
//    /**
580
//     * @return array|null
581
//     */
582
//    public function getItem(): ?array
583
//    {
584
//        return $this->item;
585
//    }
586
//
587
//    /**
588
//     * @param array|null $item
589
//     */
590
//    public function setItem(?array $item): void
591
//    {
592
//        $this->item = $item;
593
//    }
594
}
595