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

TorrentUtils::buildPoint()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 27
rs 8.5806
cc 4
eloc 18
nc 8
nop 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TorrentUtils::getTorrentAgeInDays() 0 4 1
A TorrentUtils::getSizeInGb() 0 5 1
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