Completed
Push — GildedRose/AlbertAndMarcos ( c4eed1 )
by Albert
02:33
created

BackstagePassItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getQualityMagnitudeForNextUpdate() 0 14 4
A concertHasStartedOrHasBeenCelebrated() 0 4 1
A concertDateIsVeryClose() 0 4 1
A concertDateIsClose() 0 4 1
1
<?php
2
namespace Kata\GildedRoseKata;
3
4
final class BackstagePassItem extends BaseItem
5
{
6
    const ITEM_NAME = 'Backstage passes to a TAFKAL80ETC concert';
7
    const DEGRADE_WITH_TIME = false;
8
9
    const DAYS_TO_BE_VERY_CLOSE = 5;
10
    const DAYS_TO_BE_CLOSE = 10;
11
12 5
    protected function getQualityMagnitudeForNextUpdate()
13
    {
14 5
        if ($this->concertHasStartedOrHasBeenCelebrated()) {
15 1
            return -$this->item->quality;
16
        }
17 5
        if ($this->concertDateIsVeryClose()) {
18 3
            return 3;
19
        }
20 2
        if ($this->concertDateIsClose()) {
21 1
            return 2;
22
        }
23
24 1
        return 1;
25
    }
26
27 5
    private function concertHasStartedOrHasBeenCelebrated()
28
    {
29 5
        return $this->item->sell_in <= 0;
30
    }
31
32 5
    private function concertDateIsVeryClose()
33
    {
34 5
        return $this->item->sell_in <= self::DAYS_TO_BE_VERY_CLOSE;
35
    }
36
37 2
    private function concertDateIsClose()
38
    {
39 2
        return $this->item->sell_in <= self::DAYS_TO_BE_CLOSE;
40
    }
41
}
42