Month   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isOutOfMonth() 0 4 1
A __construct() 0 12 2
A fromMonth() 0 4 1
A current() 0 4 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