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