Completed
Push — master ( 31bd22...bc5986 )
by Mauro
04:15
created

Ad   F

Complexity

Total Complexity 47

Size/Duplication

Total Lines 533
Duplicated Lines 0 %

Coupling/Cohesion

Components 14
Dependencies 2

Test Coverage

Coverage 97.84%

Importance

Changes 0
Metric Value
wmc 47
lcom 14
cbo 2
dl 0
loc 533
ccs 136
cts 139
cp 0.9784
rs 3.6421
c 0
b 0
f 0

33 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 9 2
A setId() 0 5 1
A getAdsType() 0 9 2
A setAdsType() 0 5 1
A getCity() 0 9 2
A setCity() 0 5 1
A getContent() 0 9 2
A setContent() 0 5 1
A getEmail() 0 9 2
A setEmail() 0 5 1
A getDistrict() 0 4 1
A setDistrict() 0 5 1
A getModify() 0 9 2
A setModify() 0 5 1
A getOperation() 0 9 2
A setOperation() 0 5 1
A setPayment() 0 5 1
A getPayment() 0 4 1
A getPhone() 0 9 2
A setPhone() 0 5 1
A addPicture() 0 5 1
A getPictures() 0 9 2
A setPictures() 0 5 1
A getPrice() 0 9 2
A setPrice() 0 5 1
A getRegion() 0 9 2
A setRegion() 0 5 1
A getStatus() 0 9 2
A setStatus() 0 5 1
A getTitle() 0 9 2
A setTitle() 0 5 1
A getType() 0 9 2
A setType() 0 5 1

How to fix   Complexity   

Complex Class

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

1
<?php
2
/*
3
 * This file is part of the La Voz Feed Generator package.
4
 *
5
 * (c) Zephia <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zephia\LaVozFeed\Entity;
12
13
use Zephia\LaVozFeed\Exception\LogicException;
14
15
/**
16
 * Class Ad
17
 *
18
 * @package Zephia\LaVozFeed\Entity
19
 * @author  Mauro Moreno <[email protected]>
20
 */
21
class Ad extends Entity
22
{
23
    /**
24
     * @var string
25
     */
26
    private $id = '';
27
28
    /**
29
     * @var string
30
     */
31
    private $ads_type = '';
32
33
    /**
34
     * @var string
35
     */
36
    private $city = '';
37
38
    /**
39
     * @var string
40
     */
41
    private $content = '';
42
43
    /**
44
     * @var District
45
     */
46
    private $district;
47
48
    /**
49
     * @var Email
50
     */
51
    private $email;
52
53
    /**
54
     * @var \DateTime
55
     */
56
    private $modify;
57
58
    /**
59
     * @var string
60
     */
61
    private $operation = '';
62
63
    /**
64
     * @var string
65
     */
66
    private $payment = '';
67
68
    /**
69
     * @var Phone
70
     */
71
    private $phone;
72
73
    /**
74
     * @var array
75
     */
76
    private $pictures = [];
77
78
    /**
79
     * @var Price
80
     */
81
    private $price;
82
83
    /**
84
     * @var string
85
     */
86
    private $region = '';
87
88
    /**
89
     * @var string
90
     */
91
    private $status = '';
92
93
    /**
94
     * @var string
95
     */
96
    private $title = '';
97
98
    /**
99
     * @var string
100
     */
101
    private $type = '';
102
103
    /**
104
     * Get Id
105
     *
106
     * @return string
107
     */
108 6
    public function getId()
109
    {
110 6
        if (empty($this->id)) {
111 2
            throw new LogicException(
112 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'id')
113 2
            );
114
        }
115 4
        return $this->id;
116
    }
117
118
    /**
119
     * Set Id
120
     *
121
     * @param string $id
122
     *
123
     * @return Ad
124
     */
125 4
    public function setId($id)
126
    {
127 4
        $this->id = $id;
128 4
        return $this;
129
    }
130
131
    /**
132
     * Get Ads Type
133
     *
134
     * @return string
135
     */
136 6
    public function getAdsType()
137
    {
138 6
        if (empty($this->ads_type)) {
139 2
            throw new LogicException(
140 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'ads_type')
141 2
            );
142
        }
143 4
        return $this->ads_type;
144
    }
145
146
    /**
147
     * Set Ads Type
148
     *
149
     * @param string $ads_type
150
     *
151
     * @return Ad
152
     */
153 4
    public function setAdsType($ads_type)
154
    {
155 4
        $this->ads_type = $ads_type;
156 4
        return $this;
157
    }
158
159
    /**
160
     * Get City
161
     *
162
     * @return string
163
     */
164 6
    public function getCity()
165
    {
166 6
        if (empty($this->city)) {
167 2
            throw new LogicException(
168 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'city')
169 2
            );
170
        }
171 4
        return $this->city;
172
    }
173
174
    /**
175
     * Set City
176
     *
177
     * @param string $city
178
     *
179
     * @return Ad
180
     */
181 4
    public function setCity($city)
182
    {
183 4
        $this->city = $city;
184 4
        return $this;
185
    }
186
187
    /**
188
     * Get Content
189
     *
190
     * @return string
191
     */
192 6
    public function getContent()
193
    {
194 6
        if (empty($this->content)) {
195 2
            throw new LogicException(
196 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'content')
197 2
            );
198
        }
199 4
        return $this->content;
200
    }
201
202
    /**
203
     * Set Content
204
     *
205
     * @param string $content
206
     *
207
     * @return Ad
208
     */
209 4
    public function setContent($content)
210
    {
211 4
        $this->content = $content;
212 4
        return $this;
213
    }
214
215
    /**
216
     * Get Email
217
     *
218
     * @return string
219
     */
220 6
    public function getEmail()
221
    {
222 6
        if (empty($this->email)) {
223 2
            throw new LogicException(
224 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'email')
225 2
            );
226
        }
227 4
        return $this->email;
228
    }
229
230
    /**
231
     * Set Email
232
     *
233
     * @param Email $email
234
     *
235
     * @return Ad
236
     */
237 4
    public function setEmail(Email $email)
238
    {
239 4
        $this->email = $email;
240 4
        return $this;
241
    }
242
243
    /**
244
     * Get District
245
     *
246
     * @return District
247
     */
248 1
    public function getDistrict()
249
    {
250 1
        return $this->district;
251
    }
252
253
    /**
254
     * Set District
255
     *
256
     * @param District $district
257
     *
258
     * @return Ad
259
     */
260 3
    public function setDistrict(District $district)
261
    {
262 3
        $this->district = $district;
263 3
        return $this;
264
    }
265
266
    /**
267
     * Get Modify
268
     *
269
     * @return \DateTime
270
     */
271 6
    public function getModify()
272
    {
273 6
        if (empty($this->modify)) {
274 2
            throw new LogicException(
275 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'modify')
276 2
            );
277
        }
278 4
        return $this->modify;
279
    }
280
281
    /**
282
     * Set Modify
283
     *
284
     * @param \DateTime $modify
285
     *
286
     * @return Ad
287
     */
288 4
    public function setModify($modify)
289
    {
290 4
        $this->modify = $modify;
291 4
        return $this;
292
    }
293
294
    /**
295
     * Get Operation
296
     *
297
     * @return string
298
     */
299 6
    public function getOperation()
300
    {
301 6
        if (empty($this->operation)) {
302 2
            throw new LogicException(
303 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'operation')
304 2
            );
305
        }
306 4
        return $this->operation;
307
    }
308
309
    /**
310
     * Set Operation
311
     *
312
     * @param string $operation
313
     *
314
     * @return Ad
315
     */
316 4
    public function setOperation($operation)
317
    {
318 4
        $this->operation = $operation;
319 4
        return $this;
320
    }
321
322
    /**
323
     * Set Payment
324
     *
325
     * @param string $payment
326
     *
327
     * @return Ad
328
     */
329 4
    public function setPayment($payment)
330
    {
331 4
        $this->payment = $payment;
332 4
        return $this;
333
    }
334
335
    /**
336
     * Get Payment
337
     *
338
     * @return string
339
     */
340 4
    public function getPayment()
341
    {
342 4
        return $this->payment;
343
    }
344
345
    /**
346
     * Get Phone
347
     *
348
     * @return Phone
349
     */
350 6
    public function getPhone()
351
    {
352 6
        if (empty($this->phone)) {
353 2
            throw new LogicException(
354 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'phone')
355 2
            );
356
        }
357 4
        return $this->phone;
358
    }
359
360
    /**
361
     * Set Phone
362
     *
363
     * @param Phone $phone
364
     *
365
     * @return Ad
366
     */
367 4
    public function setPhone(Phone $phone)
368
    {
369 4
        $this->phone = $phone;
370 4
        return $this;
371
    }
372
373
    /**
374
     * Add Picture
375
     *
376
     * @param Picture $picture
377
     *
378
     * @return Ad
379
     */
380 2
    public function addPicture(Picture $picture)
381
    {
382 2
        $this->pictures[] = $picture;
383 2
        return $this;
384
    }
385
386
    /**
387
     * Get Pictures
388
     *
389
     * @return array
390
     */
391 4
    public function getPictures()
392
    {
393 4
        if (count($this->pictures) === 0) {
394 2
            throw new LogicException(
395 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'pictures')
396 2
            );
397
        }
398 2
        return $this->pictures;
399
    }
400
401
    /**
402
     * Set Pictures
403
     *
404
     * @param array $pictures
405
     *
406
     * @return Ad
407
     */
408
    public function setPictures($pictures)
409
    {
410
        $this->pictures = $pictures;
411
        return $this;
412
    }
413
414
    /**
415
     * Get Price
416
     *
417
     * @return Price
418
     */
419 6
    public function getPrice()
420
    {
421 6
        if (empty($this->price)) {
422 2
            throw new LogicException(
423 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'price')
424 2
            );
425
        }
426 4
        return $this->price;
427
    }
428
429
    /**
430
     * Set Price
431
     *
432
     * @param Price $price
433
     *
434
     * @return Ad
435
     */
436 4
    public function setPrice($price)
437
    {
438 4
        $this->price = $price;
439 4
        return $this;
440
    }
441
442
    /**
443
     * Get Region
444
     *
445
     * @return string
446
     */
447 6
    public function getRegion()
448
    {
449 6
        if (empty($this->region)) {
450 2
            throw new LogicException(
451 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'region')
452 2
            );
453
        }
454 4
        return $this->region;
455
    }
456
457
    /**
458
     * Set Region
459
     *
460
     * @param string $region
461
     *
462
     * @return Ad
463
     */
464 4
    public function setRegion($region)
465
    {
466 4
        $this->region = $region;
467 4
        return $this;
468
    }
469
470
    /**
471
     * Get Status
472
     *
473
     * @return string
474
     */
475 6
    public function getStatus()
476
    {
477 6
        if (empty($this->status)) {
478 2
            throw new LogicException(
479 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'status')
480 2
            );
481
        }
482 4
        return $this->status;
483
    }
484
485
    /**
486
     * Set Status
487
     *
488
     * @param string $status
489
     *
490
     * @return Ad
491
     */
492 4
    public function setStatus($status)
493
    {
494 4
        $this->status = $status;
495 4
        return $this;
496
    }
497
498
    /**
499
     * Get Title
500
     *
501
     * @return string
502
     */
503 6
    public function getTitle()
504
    {
505 6
        if (empty($this->title)) {
506 2
            throw new LogicException(
507 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'title')
508 2
            );
509
        }
510 4
        return $this->title;
511
    }
512
513
    /**
514
     * Set Title
515
     *
516
     * @param string $title
517
     *
518
     * @return Ad
519
     */
520 4
    public function setTitle($title)
521
    {
522 4
        $this->title = $title;
523 4
        return $this;
524
    }
525
526
    /**
527
     * Get Type
528
     *
529
     * @return string
530
     */
531 6
    public function getType()
532
    {
533 6
        if (empty($this->type)) {
534 2
            throw new LogicException(
535 2
                sprintf(self::ERROR_MISSING_ATTRIBUTE_FORMAT, 'type')
536 2
            );
537
        }
538 4
        return $this->type;
539
    }
540
541
    /**
542
     * Set Type
543
     *
544
     * @param string $type
545
     *
546
     * @return Ad
547
     */
548 4
    public function setType($type)
549
    {
550 4
        $this->type = $type;
551 4
        return $this;
552
    }
553
}
554