GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DateTimeHelper   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getDatesListByPeriod() 0 15 6
B executeByPeriod() 0 13 5
1
<?php
2
/**
3
 * Helper for works with date and time
4
 *
5
 * @author Kachit
6
 * @package Kachit\Helper
7
 */
8
namespace Kachit\Helper;
9
10
class DateTimeHelper
11
{
12
    // Second amounts for various time increments
13
    const YEAR = 31556926;
14
    const LEAP_YEAR = 31622400;
15
    const MONTH = 2629744;
16
    const WEEK = 604800;
17
    const DAY = 86400;
18
    const HOUR = 3600;
19
    const MINUTE = 60;
20
21
    const DATEFORMAT_MYSQL_DATE = 'Y-m-d';
22
    const DATEFORMAT_MYSQL_DATETIME = 'Y-m-d H:i:s';
23
24
    /**
25
     * Get dates by period
26
     *
27
     * @param mixed $startDate
28
     * @param mixed $endDate
29
     * @param string $format
30
     * @param int $step
31
     * @return array
32
     * @throws \Exception
33
     */
34
    public function getDatesListByPeriod($startDate, $endDate, $format = null, $step = self::DAY)
35
    {
36
        $startTimestamp = (is_int($startDate)) ? $startDate : strtotime($startDate);
37
        $endTimestamp = (is_int($endDate)) ? $endDate : strtotime($endDate);
38
        if ($startTimestamp >= $endTimestamp) {
39
            throw new \Exception('Dates interval is not valid');
40
        }
41
        $dates = [];
42
        $current = $startTimestamp;
43
        while($current <= $endTimestamp) {
44
            $dates[] = ($format) ? date($format, $current) : $current;
45
            $current += $step;
46
        }
47
        return $dates;
48
    }
49
50
    /**
51
     * Execute by period
52
     *
53
     * @param mixed $startDate
54
     * @param mixed $endDate
55
     * @param \Closure $function
56
     * @param int $step
57
     * @throws \Exception
58
     */
59
    public function executeByPeriod($startDate, $endDate, $function, $step = self::DAY)
60
    {
61
        $startTimestamp = (is_int($startDate)) ? $startDate : strtotime($startDate);
62
        $endTimestamp = (is_int($endDate)) ? $endDate : strtotime($endDate);
63
        if ($startTimestamp >= $endTimestamp) {
64
            throw new \Exception('Dates interval is not valid');
65
        }
66
        $current = $startTimestamp;
67
        while($current <= $endTimestamp) {
68
            $function($current);
69
            $current += $step;
70
        }
71
    }
72
}