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.
Completed
Push — master ( f6a036...6a28d0 )
by Denis
02:35
created

ExcelHelper::convertDateTime()   C

Complexity

Conditions 14
Paths 32

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 40
rs 5.0864
cc 14
eloc 26
nc 32
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Ellumilel\Helpers;
3
4
/**
5
 * Class PHPExcelHelper
6
 * @package Ellumilel\Helpers
7
 */
8
class ExcelHelper
9
{
10
    /**
11
     * @link http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx
12
     * XFE1048577
13
     */
14
    const EXCEL_MAX_ROW = 1048576;
15
    const EXCEL_MAX_RANGE = 2147483647;
16
    const EXCEL_MAX_COL = 16384;
17
18
    /**
19
     * @param string $dateInput
20
     *
21
     * @return mixed
22
     */
23
    public static function convertDateTime($dateInput)
24
    {
25
        $epoch = 1900;
26
        $norm = 300;
27
        $year = $month = $day = $offset = $seconds = 0;
28
        $dateTime = $dateInput;
29
        if (preg_match("/(\d{4})\-(\d{2})\-(\d{2})/", $dateTime, $matches)) {
30
            $year = $matches[1];
31
            $month = $matches[2];
32
            $day = $matches[3];
33
        }
34
35
        if (preg_match("/(\d{2}):(\d{2}):(\d{2})/", $dateTime, $matches)) {
36
            $seconds = ($matches[1] * 60 * 60 + $matches[2] * 60 + $matches[3]) / 86400;
37
        }
38
39
        if ("$year-$month-$day" == '1899-12-31' || "$year-$month-$day" == '1900-01-00') {
40
            return $seconds;
41
        }
42
        if ("$year-$month-$day" == '1900-02-29') {
43
            return 60 + $seconds;
44
        }
45
        $range = $year - $epoch;
46
        // check leapDay
47
        $leap = (new \DateTime($dateInput))->format('L');
48
        $mDays = [31, ($leap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
49
50
        if (($year < 1900 || $year > 9999) || ($month < 1 || $month > 12) || $day < 1 || $day > $mDays[$month - 1]) {
51
            return 0;
52
        }
53
54
        $days = $day + ($range * 365) + array_sum(array_slice($mDays, 0, $month - 1));
55
        $days += intval(($range) / 4) - intval(($range + $offset) / 100);
56
        $days += intval(($range + $offset + $norm) / 400) - intval($leap);
57
        if ($days > 59) {
58
            $days++;
59
        }
60
61
        return $days + $seconds;
62
    }
63
64
    /**
65
     * @param $val
66
     *
67
     * @return mixed
68
     */
69
    public static function xmlspecialchars($val)
70
    {
71
        return str_replace("'", "&#39;", htmlspecialchars($val));
72
    }
73
74
    /**
75
     * @param int $rowNumber
76
     * @param int $columnNumber
77
     *
78
     * @return string Cell label/coordinates (A1, C3, AA42)
79
     */
80
    public static function xlsCell($rowNumber, $columnNumber)
81
    {
82
        $n = $columnNumber;
83
        for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) {
84
            $r = chr($n % 26 + 0x41).$r;
85
        }
86
87
        return $r.($rowNumber + 1);
88
    }
89
90
    /**
91
     * @link https://msdn.microsoft.com/ru-RU/library/aa365247%28VS.85%29.aspx
92
     *
93
     * @param string $filename
94
     *
95
     * @return mixed
96
     */
97
    public static function checkFilename($filename)
98
    {
99
        $invalidCharacter = array_merge(
100
            array_map('chr', range(0, 31)),
101
            ['<', '>', '?', '"', ':', '|', '\\', '/', '*', '&']
102
        );
103
104
        return str_replace($invalidCharacter, '', $filename);
105
    }
106
107
    /**
108
     * @todo  check escaping
109
     *
110
     * @param string $cellFormat
111
     *
112
     * @return string
113
     */
114
    public static function escapeCellFormat($cellFormat)
115
    {
116
        $ignoreUntil = '';
117
        $escaped = '';
118
        for ($i = 0, $ix = strlen($cellFormat); $i < $ix; $i++) {
119
            $c = $cellFormat[$i];
120
            if ($ignoreUntil == '' && $c == '[') {
121
                $ignoreUntil = ']';
122
            } else {
123
                if ($ignoreUntil == '' && $c == '"') {
124
                    $ignoreUntil = '"';
125
                } else {
126
                    if ($ignoreUntil == $c) {
127
                        $ignoreUntil = '';
128
                    }
129
                }
130
            }
131
            if ($ignoreUntil == '' &&
132
                ($c == ' ' || $c == '-' || $c == '(' || $c == ')') &&
133
                ($i == 0 || $cellFormat[$i - 1] != '_')
134
            ) {
135
                $escaped .= "\\".$c;
136
            } else {
137
                $escaped .= $c;
138
            }
139
        }
140
141
        return $escaped;
142
    }
143
}
144