DateRange   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 30
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 Methods
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * Get current month's days range.
23
     *
24
     * @param  string  $keyFormat
25
     * @param  string  $interval
26
     *
27
     * @return array
28
     */
29
    public static function getCurrentMonthDaysRange($keyFormat = 'Y-m-d', $interval = '1 day')
30
    {
31
        $start = Carbon::now()->subMonth(1)->setTime(0, 0);
32
        $end   = Carbon::now()->setTime(23, 59, 59);
33
34
        $range = new Collection;
35
36
        /** @var  \Carbon\Carbon  $period */
37
        foreach (new DatePeriod($start, DateInterval::createFromDateString($interval), $end) as $period) {
38
            $range->put($period->format($keyFormat), $period);
39
        }
40
41
        return compact('start', 'end', 'range');
42
    }
43
}
44