Period::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace SchulzeFelix\SearchConsole;
4
5
use Carbon\Carbon;
6
use SchulzeFelix\SearchConsole\Exceptions\InvalidPeriod;
7
8
class Period
9
{
10
    /** @var Carbon */
11
    public $startDate;
12
13
    /** @var Carbon */
14
    public $endDate;
15
16
    public static function create(Carbon $startDate, Carbon $endDate): self
17
    {
18
        return new static($startDate, $endDate);
19
    }
20
21
    public function __construct(Carbon $startDate, Carbon $endDate)
22
    {
23
        if ($startDate > $endDate) {
24
            throw InvalidPeriod::startDateCannotBeAfterEndDate($startDate, $endDate);
25
        }
26
27
        $this->startDate = $startDate;
28
29
        $this->endDate = $endDate;
30
    }
31
}
32