Completed
Push — master ( 6a6fc8...07e153 )
by Stanislav
02:24
created

TorrentUtils::getLastPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 12
nc 2
nop 3
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 / 1000 / 1000 / 1000, $round);
31
    }
32
}
33