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

TorrentUtils::getTorrentsSize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B TorrentUtils::getTorrentAge() 0 7 5
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