Passed
Push — master ( 175068...a4dc57 )
by Guillaume
10:02
created

Alfred4::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 10
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Docsets;
4
5
use Godbout\DashDocsetBuilder\Docsets\BaseDocset;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Facades\Storage;
8
use Wa72\HtmlPageDom\HtmlPageCrawler;
9
10
class Alfred4 extends BaseDocset
11
{
12
    public const CODE = 'alfred-4';
13
    public const NAME = 'Alfred 4';
14
    public const URL = 'www.alfredapp.com';
15
    public const INDEX = 'help/index.html';
16
    public const PLAYGROUND = '';
17
    public const ICON_16 = 'favicon-16x16.png';
18
    public const ICON_32 = 'favicon-32x32.png';
19
    public const EXTERNAL_DOMAINS = [
20
        'fonts.googleapis.com',
21
    ];
22
23
24
    public function grab(): bool
25
    {
26
        $toIgnore = implode('|', [
0 ignored issues
show
Unused Code introduced by
The assignment to $toIgnore is dead and can be removed.
Loading history...
27
        ]);
28
29
        $toGet = implode('|', [
30
           '\.css',
31
            '\.ico',
32
            '\.js',
33
            '\.png',
34
            '\.svg',
35
            '/css',
36
            '/help'
37
        ]);
38
39
        system(
40
            "echo; wget www.alfredapp.com/help \
41
                --mirror \
42
                --trust-server-names \
43
                --accept-regex='{$toGet}' \
44
                --ignore-case \
45
                --page-requisites \
46
                --adjust-extension \
47
                --convert-links \
48
                --span-hosts \
49
                --domains={$this->externalDomains()} \
50
                --directory-prefix=storage/{$this->downloadedDirectory()} \
51
                -e robots=off \
52
                --quiet \
53
                --show-progress",
54
            $result
55
        );
56
57
        return $result === 0;
58
    }
59
60
    public function entries(string $file): Collection
61
    {
62
        $crawler = HtmlPageCrawler::create(Storage::get($file));
63
64
        $crawler->filter('h1')->each(function (HtmlPageCrawler $node) use ($entries) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $entries seems to be never defined.
Loading history...
Unused Code introduced by
The parameter $node is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
        $crawler->filter('h1')->each(function (/** @scrutinizer ignore-unused */ HtmlPageCrawler $node) use ($entries) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
            $entries->push([
66
                'name' => 'What Shows up in Dash',
67
                'type' => 'One of the Million of Dash Entry Type',
68
                'path' => 'The Path to the File',
69
            ]);
70
        });
71
72
        return $entries;
73
    }
74
75
    public function format(string $file): string
76
    {
77
        $crawler = HtmlPageCrawler::create(Storage::get($file));
78
79
        /**
80
         * This is equivalent to murder
81
         */
82
        $crawler->filter('body')->remove();
83
84
        return $crawler->saveHTML();
85
    }
86
}
87