functions.php ➔ seconds2minutes()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 18
ccs 9
cts 10
cp 0.9
crap 4.016
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace FilmTools\SecondsToMinutes;
3
4
5
/**
6
 * @todo   Can we avoid rounding the $seconds when instantiating the DateTime?
7
 *
8
 * @param  int $seconds
9
 * @return string|int
10
 */
11
function seconds2minutes( $seconds )
12
{
13 40
    if (is_array($seconds))
14
        return array_map('seconds2minutes', $seconds);
15
16 40
    if (!is_numeric( $seconds )):
17 4
        return $seconds;
18
    endif;
19
20 36
    $s = $seconds % 60;
21 36
    $m = floor(($seconds % 3600)/60);
22 36
    $h = floor($seconds /3600);
23
24 36
    if ($h)
25 24
        return sprintf("%02d:%02d:%02d", $h, $m, $s);
26 12
    return sprintf("%02d:%02d", $m, $s);
27
28
}
29