Completed
Push — feature/player-elo ( 2693b2...03d3b5 )
by Vladimir
04:10
created

Season   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 23.08%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 2
dl 0
loc 73
rs 10
c 0
b 0
f 0
ccs 6
cts 26
cp 0.2308

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getSeason() 0 7 1
B getCurrentSeason() 0 16 8
B getCurrentSeasonRange() 0 20 5
A getWinterSeason() 0 4 1
A getSpringSeason() 0 4 1
A getSummerSeason() 0 4 1
A getFallSeason() 0 4 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 5
    public static function getSeason(DateTime $dateTime)
13
    {
14 5
        return [
15
            'season' => self::getCurrentSeason((int)$dateTime->format('n')),
16 5
            'year'   => (int)$dateTime->format('Y'),
17
        ];
18 5
    }
19
20 5
    public static function getCurrentSeason($month = null)
21 5
    {
22
        if ($month === null) {
23
            $month = Carbon::now()->month;
24
        }
25
26
        if (1 <= $month && $month <= 3) {
27
            return self::WINTER;
28
        } elseif (4 <= $month && $month <= 6) {
29
            return self::SPRING;
30
        } elseif (7 <= $month && $month <= 9) {
31
            return self::SUMMER;
32
        }
33
34
        return self::FALL;
35
    }
36
37
    public static function getCurrentSeasonRange($season = null)
38
    {
39
        if ($season === null) {
40
            $season = self::getCurrentSeason();
41
        }
42
43
        switch ($season) {
44
            case self::WINTER:
45
                return self::getWinterSeason();
46
47
            case self::SPRING:
48
                return self::getSpringSeason();
49
50
            case self::SUMMER:
51
                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
    public static function getSummerSeason()
69
    {
70
        return (new MonthDateRange('July', 'September'));
71
    }
72
73
    public static function getFallSeason()
74
    {
75
        return (new MonthDateRange('October', 'December'));
76
    }
77
}
78