TorrentMenuItemBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A buildTitle() 0 5 1
A subtitle() 0 3 1
A pageLink() 0 3 1
A buildTimeagoValue() 0 7 1
A title() 0 9 1
1
<?php
2
3
namespace Godbout\Alfred\Kat;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class TorrentMenuItemBuilder
8
{
9 12
    public static function title(Crawler $row)
10
    {
11 12
        $itemMetada = [];
12
13 12
        $row->children('td')->nextAll()->each(function ($column) use (&$itemMetada) {
14 12
            $itemMetada[] = trim($column->text());
15 12
        });
16
17 12
        return trim(self::buildTitle($itemMetada));
18
    }
19
20 12
    public static function subtitle(Crawler $row)
21
    {
22 12
        return trim(strstr(trim($row->text('', false)), PHP_EOL, true));
23
    }
24
25 12
    public static function pageLink(Crawler $row)
26
    {
27 12
        return $row->children('td a.cellMainLink')->eq(0)->attr('href');
28
    }
29
30 12
    protected static function buildTitle($metadata)
31
    {
32 12
        [$timeagoNumericPart, $timeagoAlphaPart] = self::buildTimeagoValue($metadata[2]);
33
34 12
        return "$timeagoNumericPart $timeagoAlphaPart ago by $metadata[1], $metadata[0], $metadata[3] seeders ($metadata[4] l)";
35
    }
36
37 12
    protected static function buildTimeagoValue($timeago)
38
    {
39 12
        $numbericPart = intval($timeago);
40
41 12
        $alphaPart = str_replace($numbericPart, '', $timeago);
42
43 12
        return [$numbericPart, $alphaPart];
44
    }
45
}
46