TorrentUtils::getSizeInGb()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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