Completed
Push — master ( 633079...840c2c )
by Frederick
11s
created

DateChecker::validateDateRange()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 1
nop 2
1
<?php
2
3
namespace Vanbrabantf\NpmStatFetcher\Helpers;
4
5
6
use Cake\Chronos\Chronos;
7
use DateTimeInterface;
8
use Vanbrabantf\NpmStatFetcher\Exceptions\DateException;
9
10
class DateChecker
11
{
12
    public static function validateDateRange(DateTimeInterface $start, DateTimeInterface $end)
13
    {
14
        $start = new Chronos($start);
0 ignored issues
show
Bug introduced by
$start of type DateTimeInterface is incompatible with the type null|string expected by parameter $time of Cake\Chronos\Chronos::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

14
        $start = new Chronos(/** @scrutinizer ignore-type */ $start);
Loading history...
15
        $end = new Chronos($end);
16
17
        if (
18
            $start->isFuture() ||
19
            $end->isFuture() ||
20
            $start > $end
21
        ) {
22
            throw new DateException('Date range is incorrect');
23
        }
24
25
        return true;
26
    }
27
}
28