Passed
Push — master ( 79c4f7...80a53d )
by Guillaume
12:18
created

DocsetGrabber   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 3
b 0
f 0
dl 0
loc 49
ccs 14
cts 18
cp 0.7778
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A wgetOptions() 0 12 1
A sitemapExists() 0 3 1
A grabFromIndex() 0 8 1
A grabFromSitemap() 0 10 1
1
<?php
2
3
namespace App\Services;
4
5
use App\Contracts\Docset;
6
7
final class DocsetGrabber
8
{
9
    public $docset;
10
11
12 36
    public function __construct(Docset $docset)
13
    {
14 36
        $this->docset = $docset;
15 36
    }
16
17 1
    public function sitemapExists()
18
    {
19 1
        return @file_get_contents("https://{$this->docset->url()}/sitemap.xml");
20
    }
21
22 1
    public function grabFromSitemap()
23
    {
24 1
        system(
25 1
            "wget {$this->docset->url()}/sitemap.xml --quiet --output-document - | \
26 1
            egrep --only-matching '{$this->docset->url()}[^<]+' | \
27 1
            wget --input-file - {$this->wgetOptions()}",
28
            $result
29
        );
30
31 1
        return $result === 0;
32
    }
33
34
    public function grabFromIndex()
35
    {
36
        system(
37
            "wget {$this->docset->url()} {$this->wgetOptions()}",
38
            $result
39
        );
40
41
        return $result === 0;
42
    }
43
44 1
    protected function wgetOptions()
45
    {
46
        return "--mirror \
47
            -e robots=off \
48
            --page-requisites \
49
            --adjust-extension \
50
            --convert-links \
51
            --no-directories \
52
            --span-hosts \
53 1
            --domains={$this->docset->externalDomains()} \
54
            --quiet \
55 1
            --directory-prefix=storage/{$this->docset->downloadedDirectory()}";
56
    }
57
}
58