DatesConfig::getWeeksEndsOn()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4
1
<?php
2
3
namespace DavisPeixoto\ReportDates;
4
5
use DateTimeZone;
6
7
class DatesConfig
8
{
9
    /**
10
     * @var DateTimeZone
11
     */
12
    private $timezone;
13
14
    /**
15
     * @var DayNumber
16
     */
17
    private $weeksStartsOn;
18
19
    /**
20
     * @var DayNumber[]
21
     */
22
    private $businessDays;
23
24
    /**
25
     * DatesConfig constructor.
26
     *
27
     * @param DateTimeZone|null $timezone
28
     * @param DayNumber|null $weeksStartsOn
29
     * @param DayNumber[]|null $businessDays
30
     */
31 8
    public function __construct(
32
        DateTimeZone $timezone = null,
33
        DayNumber $weeksStartsOn = null,
34
        array $businessDays = null
35
    ) {
36 8
        $this->timezone = $timezone ?? new DateTimeZone('UTC');
37 8
        $this->weeksStartsOn = $weeksStartsOn ?? new DayNumber(DayNumber::SUNDAY);
38 8
        $this->businessDays = $businessDays ?? [
39 4
            new DayNumber(DayNumber::MONDAY),
40 4
            new DayNumber(DayNumber::TUESDAY),
41 4
            new DayNumber(DayNumber::WEDNESDAY),
42 4
            new DayNumber(DayNumber::THURSDAY),
43 4
            new DayNumber(DayNumber::FRIDAY)
44
        ];
45 8
    }
46
47
    /**
48
     * @return DateTimeZone
49
     */
50 8
    public function getTimezone(): DateTimeZone
51
    {
52 8
        return $this->timezone;
53
    }
54
55
    /**
56
     * @return DayNumber
57
     */
58 8
    public function getWeeksStartsOn(): DayNumber
59
    {
60 8
        return $this->weeksStartsOn;
61
    }
62
63
    /**
64
     * @return DayNumber[]
65
     */
66 14
    public function getBusinessDays(): array
67
    {
68 14
        return $this->businessDays;
69
    }
70
71
    /**
72
     * @return DayNumber
73
     */
74 8
    public function getWeeksEndsOn(): DayNumber
75
    {
76 8
        $output = new DayNumber(DayNumber::SATURDAY);
77
78 8
        if (!$this->weeksStartsOn->equals(new DayNumber(DayNumber::SUNDAY))) {
79 4
            $aux = (int)$this->weeksStartsOn->getValue() - 1;
80
81 4
            foreach (DayNumber::values() as $day) {
82 4
                if ((int)$day->getValue() === $aux) {
83 4
                    $output = clone $day;
84 4
                    break;
85
                }
86
            }
87
        }
88
89 8
        return $output;
90
    }
91
}
92