Completed
Push — master ( 3f7578...5307b5 )
by ARCANEDEV
04:28
created

DateRange   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCurrentMonthDaysRange() 0 14 2
1
<?php namespace Arcanesoft\Tracker\Support;
2
3
use Carbon\Carbon;
4
use DateInterval;
5
use DatePeriod;
6
use Illuminate\Support\Collection;
7
8
/**
9
 * Class     DateRange
10
 *
11
 * @package  Arcanesoft\Tracker\Support
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class DateRange
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Main Functions
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Get current month's days range.
22
     *
23
     * @param  string  $keyFormat
24
     * @param  string  $interval
25
     *
26
     * @return array
27
     */
28
    public static function getCurrentMonthDaysRange($keyFormat = 'Y-m-d', $interval = '1 day')
29
    {
30
        $start = Carbon::now()->subMonth(1)->setTime(0, 0);
31
        $end   = Carbon::now()->setTime(23, 59, 59);
32
33
        $range = new Collection;
34
35
        /** @var  \Carbon\Carbon  $period */
36
        foreach (new DatePeriod($start, DateInterval::createFromDateString($interval), $end) as $period) {
37
            $range->put($period->format($keyFormat), $period);
38
        }
39
40
        return compact('start', 'end', 'range');
41
    }
42
}
43