Completed
Push — master ( 2eb0da...31e203 )
by Stanislav
02:21
created

TorrentUtils::buildTableData()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 34
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 8.8571
cc 3
eloc 24
nc 3
nop 1
1
<?php
2
3
namespace Popstas\Transmission\Console\Helpers;
4
5
use Martial\Transmission\API\Argument\Torrent;
6
7
class TorrentUtils
8
{
9
    /**
10
     * @param $torrent
11
     * @return int seconds from torrent finish download
12
     */
13
    public static function getTorrentAge($torrent)
14
    {
15
        $date = isset($torrent[Torrent\Get::DONE_DATE]) && $torrent[Torrent\Get::DONE_DATE] ?
16
            $torrent[Torrent\Get::DONE_DATE] :
17
            (isset($torrent[Torrent\Get::ADDED_DATE]) ? $torrent[Torrent\Get::ADDED_DATE] : 0);
18
        return $date ? time() - $date : 0;
19
    }
20
21
    public static function getTorrentAgeInDays($torrent)
22
    {
23
        return round(self::getTorrentAge($torrent) / 86400);
24
    }
25
26
    public static function getSizeInGb($sizeInBytes, $round = 2)
27
    {
28
        return round($sizeInBytes / 1024 / 1024 / 1024, $round);
29
    }
30
}
31