Completed
Push — master ( 189bb6...0d32b3 )
by Matthew
03:08
created

DataFormatterHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 41
wmc 3
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createDateRangeArray() 0 30 3
1
<?php
2
3
namespace Ps2alerts\Api\Helper;
4
5
class DataFormatterHelper
6
{
7
    /**
8
     * Returns an array of dates based off two provided dates
9
     *
10
     * @param  string $dateFrom Date to start from
11
     * @param  string $dateTo   Date to finish on
12
     *
13
     * @return array
14
     */
15
    public function createDateRangeArray($dateFrom, $dateTo)
16
    {
17
        $dates = [];
18
19
        $dateFrom = mktime(
20
            1,
21
            0,
22
            0,
23
            substr($dateFrom, 5, 2),
24
            substr($dateFrom, 8, 2),
25
            substr($dateFrom, 0, 4)
26
        );
27
        $dateTo = mktime(
28
            1,
29
            0,
30
            0,
31
            substr($dateTo, 5, 2),
32
            substr($dateTo, 8, 2),
33
            substr($dateTo, 0, 4)
34
        );
35
36
        if ($dateTo >= $dateFrom) {
37
            array_push($dates, date('Y-m-d', $dateFrom)); // first entry
38
            while ($dateFrom < $dateTo) {
39
                $dateFrom += 86400; // add 24 hours
40
                array_push($dates, date('Y-m-d', $dateFrom));
41
            }
42
        }
43
        return $dates;
44
    }
45
}
46