Year   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A fromYear() 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 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