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

BaseItem   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 41
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getQualityMagnitudeForNextUpdate() 0 4 1
A updateQualityByDayPassed() 0 12 3
A validateQualityBoundaries() 0 10 3
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