Completed
Push — master ( 0b2f36...19d6a1 )
by Freek
08:35
created

Period::createForNumberOfDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Analytics;
4
5
use Carbon\Carbon;
6
use DateTime;
7
8
class Period
9
{
10
    /** @var \DateTime */
11
    public $startDate;
12
13
    /** @var \DateTime */
14
    public $endDate;
15
16
    public static function createForNumberOfDays(int $numberOfDays)
17
    {
18
        $endDate = Carbon::today();
19
20
        $startDate = Carbon::today()->subDays($numberOfDays)->startOfDay();
21
22
        return new static($startDate, $endDate);
23
    }
24
25
    public function __construct(DateTime $startDate, DateTime $endDate)
26
    {
27
        $this->startDate = $startDate;
28
29
        $this->endDate = $endDate;
30
    }
31
}
32