Uptime::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Uptime;
4
5
use DateInterval;
6
7
class Uptime extends DateInterval
8
{
9
    protected $seconds;
10
11
    public function __construct($time)
12
    {
13
        $this->seconds = (float) $time;
14
        list($days, $time)    = [(int) ($time / 86400), $time % 86400];
15
        list($hours, $time)   = [(int) ($time / 3600), $time % 3600];
16
        list($minutes, $time) = [(int) ($time / 60), $time % 60];
17
        $seconds = $time;
18
        parent::__construct("P{$days}DT{$hours}H{$minutes}M{$seconds}S");
19
    }
20
21
    public function __toString()
22
    {
23
        return (string) $this->seconds;
24
    }
25
26
    public function getRaw()
27
    {
28
        return $this->seconds;
29
    }
30
31
}
32