TorrentMenuItemBuilder::pageLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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