Completed
Push — dev ( 08778e...066e8b )
by
unknown
02:16
created

Time   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A timeToText() 0 13 3
A textToTime() 0 9 2
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers;
4
5
class Time
6
{
7
    /**
8
     * Transform tm timestamp to mm:ss.ccc string
9
     *
10
     * @param int $time
11
     * @param bool $milliseconds
12
     *
13
     * @return string
14
     */
15 1
    public function timeToText($time, $milliseconds = false)
16
    {
17 1
        $time = intval($time);
18 1
        $ms = "";
19 1
        if ($milliseconds) {
20 1
            $ms = ".".str_pad((abs($time) % 1000), 3, '0', STR_PAD_LEFT);
21
        }
22 1
        if ($time > 0) {
23 1
            return gmdate("i:s", $time / 1000).$ms;
24
        } else {
25 1
            return "-".gmdate("i:s", abs($time / 1000)).$ms;
26
        }
27
    }
28
29
    /**
30
     * Transform mm:ss to tm timestamp
31
     *
32
     * @param string $string formatted like mm:ss
33
     *
34
     * @return int
35
     */
36 1
    public function textToTime($string)
37
    {
38 1
        $timeLimit = explode(":", trim($string));
39 1
        if (count($timeLimit) == 1) {
40 1
            return intval($timeLimit[0] * 1000);
41
        } else {
42 1
            return intval($timeLimit[0] * 60 * 1000) + intval($timeLimit[1] * 1000);
43
        }
44
    }
45
}
46