GameDate::addWeeks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace OSS\CoreBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * @ORM\Entity
9
 */
10
class GameDate
11
{
12
    const WEEKS_PER_SEASON = 34;
13
14
    /**
15
     * @var int
16
     *
17
     * @ORM\Id
18
     * @ORM\GeneratedValue
19
     * @ORM\Column(type="integer")
20
     */
21
    private $id;
22
23
    /**
24
     * @var int
25
     *
26
     * @ORM\Column(type="integer")
27
     */
28
    private $week = 1;
29
30
    /**
31
     * @var int
32
     *
33
     * @ORM\Column(type="integer")
34
     */
35
    private $season = 1;
36
37
    /**
38
     * @return int
39
     */
40 5
    public function getSeason()
41
    {
42 5
        return $this->season;
43
    }
44
45
    /**
46
     * @return int
47
     */
48 5
    public function getWeek()
49
    {
50 5
        return $this->week;
51
    }
52
53 1
    public function incrementWeek()
54
    {
55 1
        $this->addWeeks(1);
56 1
    }
57
58
    /**
59
     * @param int $weeks
60
     */
61 4
    public function addWeeks($weeks)
62
    {
63 4
        $this->week += $weeks;
64 4
        $this->purge();
65 4
    }
66
67 4
    private function purge()
68
    {
69 4
        while ($this->week > self::WEEKS_PER_SEASON) {
70 2
            $this->season++;
71 2
            $this->week -= self::WEEKS_PER_SEASON;
72 2
        }
73 4
    }
74
}
75