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

TorrentUtils   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 7
c 7
b 0
f 1
lcom 0
cbo 0
dl 0
loc 24
rs 10

3 Methods

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