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.

Time   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A timestampToHttpDate() 0 7 2
B timeElapsed() 0 35 5
1
<?php
2
/**
3
 * Time.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Convert/display time
9
 */
10
trait Time
11
{
12
    /**
13
     * Convert timestamp to HTTP-date (RFC2616)
14
     *
15
     * For use in "Last-Modified" headers.
16
     *
17
     * @param string $timestamp
18
     * @return string|null
19
     */
20
    public static function timestampToHttpDate($timestamp)
21
    {
22
        if ($timestamp === null) {
23
            return null;
24
        }
25
        return gmdate("D, d M Y H:i:s T", strtotime($timestamp));
26
    }
27
28
    /**
29
     * Convert timestamp to x unit(plural), like "6 minutes" or "1 day".
30
     *
31
     * @param string $timestamp
32
     * @param string $lang Language
33
     * @return string Formated time: "x unit(s)" or empty string
34
     */
35
    public static function timeElapsed($timestamp, $lang = "en")
36
    {
37
        $arrayLanguages = array(
38
        "sv" => array("s" => ["sekund", "sekunder"],
39
                      "m" => ["minut", "minuter"],
40
                      "h" => ["timme", "timmar"],
41
                      "d" => ["dag", "dagar"]),
42
        "en" => array("s" => ["second", "seconds"],
43
                      "m" => ["minute", "minutes"],
44
                      "h" => ["hour", "hours"],
45
                      "d" => ["day", "days"])
46
        );
47
        
48
        $seconds = max((time() - strtotime($timestamp)), 0);
49
50
        if ($seconds < 60) {
51
            $number = $seconds;
52
            $key = "s";
53
        } elseif ($seconds < (60 * 60)) {
54
            $number = $seconds / 60;
55
            $key = "m";
56
        } elseif ($seconds < (60 * 60 * 24)) {
57
            $number = $seconds / (60 * 60);
58
            $key = "h";
59
        } else {
60
            $number = $seconds / (60 * 60 * 24);
61
            $key = "d";
62
        }
63
64
        $number = floor($number);
65
66
        $text = $arrayLanguages[$lang][$key][(($number > 1) ? 1 : 0)];
67
68
        return "$number $text";
69
    }
70
}
71