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

BaseItem::getQualityMagnitudeForNextUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: albertgarcia
5
 * Date: 15/12/16
6
 * Time: 9:58
7
 */
8
9
namespace Kata\GildedRoseKata;
10
11
class BaseItem
12
{
13
    const DEGRADE_WITH_TIME = true;
14
15
    /** @var Item */
16
    protected $item;
17
18 15
    public function __construct(Item $an_item)
19
    {
20 15
        $this->item = $an_item;
21 15
    }
22
23 4
    protected function getQualityMagnitudeForNextUpdate()
24
    {
25 4
        return 1;
26
    }
27
28 13
    public function updateQualityByDayPassed()
29
    {
30 13
        $this->item->sell_in--;
31 13
        if (true === static::DEGRADE_WITH_TIME) {
32 7
            $this->item->quality = $this->item->quality - $this->getQualityMagnitudeForNextUpdate();
33
        }
34
35 13
        if (false === static::DEGRADE_WITH_TIME) {
36 6
            $this->item->quality = $this->item->quality + $this->getQualityMagnitudeForNextUpdate();
37
        }
38 13
        $this->validateQualityBoundaries();
39 13
    }
40
41 13
    private function validateQualityBoundaries()
42
    {
43 13
        if ($this->item->quality < 0) {
44 3
            $this->item->quality = 0;
45
        }
46
47 13
        if ($this->item->quality > 50) {
48 2
            $this->item->quality = 50;
49
        }
50 13
    }
51
}
52