Completed
Push — feature/player-elo ( 21fda9...de6928 )
by Vladimir
07:43
created

Season::getSummerSeason()   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
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
use Carbon\Carbon;
4
5
abstract class Season
6
{
7
    const WINTER = 'winter';
8
    const SPRING = 'spring';
9
    const SUMMER = 'summer';
10
    const FALL = 'fall';
11
12 31
    public static function getSeason(DateTime $dateTime)
13
    {
14
        return [
15 31
            'season' => self::getCurrentSeason((int)$dateTime->format('n')),
16 31
            'year'   => (int)$dateTime->format('Y'),
17
        ];
18
    }
19
20 31
    public static function getCurrentSeason($month = null)
21
    {
22 31
        if ($month === null) {
23 29
            $month = Carbon::now()->month;
24
        }
25
26 31
        if (1 <= $month && $month <= 3) {
27
            return self::WINTER;
28 31
        } elseif (4 <= $month && $month <= 6) {
29
            return self::SPRING;
30 31
        } elseif (7 <= $month && $month <= 9) {
31 31
            return self::SUMMER;
32
        }
33
34
        return self::FALL;
35
    }
36
37 30
    public static function getCurrentSeasonRange($season = null)
38
    {
39 30
        if ($season === null) {
40
            $season = self::getCurrentSeason();
41
        }
42
43
        switch ($season) {
44 30
            case self::WINTER:
45
                return self::getWinterSeason();
46
47 30
            case self::SPRING:
48
                return self::getSpringSeason();
49
50 30
            case self::SUMMER:
51 30
                return self::getSummerSeason();
52
53
            default:
54
                return self::getFallSeason();
55
        }
56
    }
57
58
    public static function getWinterSeason()
59
    {
60
        return (new MonthDateRange('January', 'March'));
61
    }
62
63
    public static function getSpringSeason()
64
    {
65
        return (new MonthDateRange('April', 'June'));
66
    }
67
68 30
    public static function getSummerSeason()
69
    {
70 30
        return (new MonthDateRange('July', 'September'));
71
    }
72
73
    public static function getFallSeason()
74
    {
75
        return (new MonthDateRange('October', 'December'));
76
    }
77
}
78