Month::fromMonth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 2
crap 1
1
<?php
2
3
namespace DateRanger\Period;
4
5
use DateRanger\DateRange;
6
use DateTimeImmutable;
7
8
class Month extends DateRange
9
{
10 6
    public function __construct(?string $date_string = null)
11
    {
12 6
        $date = new DateTimeImmutable($date_string);
13
14 6
        $this->start = $date->modify('first day of this month')->setTime(0, 0, 0);
15 6
        $this->end = $date->modify('last day of this month')->setTime(23, 59, 59);
16
17 6
        $period = $this->getPeriod('P7D', Week::getFirstDayOfWeek($this->start()));
18 6
        foreach ($period as $week) {
19 6
            $this->dates[] = new Week($week->format('Y-m-d'));
20
        }
21 6
    }
22
23 1
    public static function fromMonth($year, $month): Month
24
    {
25 1
        return new self($year . '-' . $month . '-1');
26
    }
27
28 1
    public function isOutOfMonth(DateRange $period): bool
29
    {
30 1
        return !$this->overlaps($period);
31
    }
32
33
    /**
34
     * It's unnecessary defining this method. It's here only to allow IDE type hinting.
35
     *
36
     * @return Week
37
     */
38 1
    public function current()
39
    {
40 1
        return parent::current();
41
    }
42
}
43