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 ( c341c3...28bf7f )
by Denis
02:56
created

PHPExcelHelper   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
C convertDateTime() 0 38 14
A xmlspecialchars() 0 4 1
A xlsCell() 0 9 2
A checkFilename() 0 9 1
1
<?php
2
namespace Ellumilel\Helpers;
3
4
/**
5
 * Class PHPExcelHelper
6
 * @package Ellumilel\Helpers
7
 */
8
class PHPExcelHelper
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
            list($full, $year, $month, $day) = $matches;
0 ignored issues
show
Unused Code introduced by
The assignment to $full is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
31
        }
32
        if (preg_match("/(\d{2}):(\d{2}):(\d{2})/", $dateTime, $matches)) {
33
            list($full, $hour, $min, $sec) = $matches;
0 ignored issues
show
Unused Code introduced by
The assignment to $full is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
34
            $seconds = ($hour * 60 * 60 + $min * 60 + $sec) / 86400;
35
        }
36
        if ("$year-$month-$day" == '1899-12-31' || "$year-$month-$day" == '1900-01-00') {
37
            return $seconds;
38
        }
39
        if ("$year-$month-$day" == '1900-02-29') {
40
            return 60 + $seconds;
41
        }
42
43
        $range  = $year - $epoch;
44
        // check leapDay
45
        $leap = (new \DateTime($dateInput))->format('L');
46
        $mDays = [31, ($leap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
47
48
        if (($year < $epoch || $year > 9999) || ($month < 1 || $month > 12) || $day < 1 || $day > $mDays[$month - 1]) {
49
            return 0;
50
        }
51
52
        $days = $day + ($range * 365) + array_sum(array_slice($mDays, 0, $month - 1));
53
        $days += intval(($range) / 4) -  intval(($range + $offset) / 100);
54
        $days += intval(($range + $offset + $norm) / 400) - intval($leap);
55
56
        if ($days > 59) {
57
            $days++;
58
        }
59
        return  $days + $seconds;
60
    }
61
62
    /**
63
     * @param $val
64
     *
65
     * @return mixed
66
     */
67
    public static function xmlspecialchars($val)
68
    {
69
        return str_replace("'", "&#39;", htmlspecialchars($val));
70
    }
71
72
    /**
73
     * @param int $rowNumber
74
     * @param int $columnNumber
75
     *
76
     * @return string Cell label/coordinates (A1, C3, AA42)
77
     */
78
    public static function xlsCell($rowNumber, $columnNumber)
79
    {
80
        $n = $columnNumber;
81
        for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) {
82
            $r = chr($n % 26 + 0x41).$r;
83
        }
84
85
        return $r.($rowNumber + 1);
86
    }
87
88
    /**
89
     * @link https://msdn.microsoft.com/ru-RU/library/aa365247%28VS.85%29.aspx
90
     *
91
     * @param string $filename
92
     *
93
     * @return mixed
94
     */
95
    public static function checkFilename($filename)
96
    {
97
        $invalidCharacter = array_merge(
98
            array_map('chr', range(0, 31)),
99
            ['<', '>', '?', '"', ':', '|', '\\', '/', '*', '&']
100
        );
101
102
        return str_replace($invalidCharacter, '', $filename);
103
    }
104
}
105