Passed
Push — master ( bcbcca...8fb468 )
by Guillaume
08:29
created

DocsetGrabber::sitemapExists()   A

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
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Godbout\DashDocsetBuilder\Services;
4
5
use Godbout\DashDocsetBuilder\Contracts\Docset;
6
7
final class DocsetGrabber
8
{
9
    public $docset;
10
11
12 18
    public function __construct(Docset $docset)
13
    {
14 18
        $this->docset = $docset;
15 18
    }
16
17 6
    public function sitemapExists()
18
    {
19 6
        return @file_get_contents("https://{$this->docset->url()}/sitemap.xml");
20
    }
21
22
    public function grabFromSitemap()
23
    {
24
        system(
25
            "echo; wget {$this->docset->url()}/sitemap.xml --quiet --output-document - | \
26
            egrep --only-matching '{$this->docset->url()}[^<]+' | \
27
            wget --input-file - {$this->wgetOptions()}",
28
            $result
29
        );
30
31
        return $result === 0;
32
    }
33
34 6
    public function grabFromIndex()
35
    {
36 6
        system(
37 6
            "echo; wget {$this->docset->url()} {$this->wgetOptions()}",
38 2
            $result
39
        );
40
41 6
        return $result === 0;
42
    }
43
44 6
    protected function wgetOptions()
45
    {
46 2
        return "--mirror \
47
            --trust-server-names \
48
            --page-requisites \
49
            --adjust-extension \
50
            --convert-links \
51
            --span-hosts \
52 6
            --domains={$this->docset->externalDomains()} \
53 6
            --directory-prefix=storage/{$this->docset->downloadedDirectory()} \
54
            -e robots=off \
55
            --quiet \
56
            --show-progress";
57
    }
58
}
59