TorrentUtils   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTorrentAge() 0 7 5
A getTorrentAgeInDays() 0 4 1
A 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 / 1024 / 1024 / 1024, $round);
31
    }
32
}
33