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

DocsetBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Godbout\DashDocsetBuilder\Services;
4
5
use LaravelZero\Framework\Commands\Command;
6
use Godbout\DashDocsetBuilder\Contracts\Docset;
7
use Illuminate\Console\Command as LaravelCommand;
8
9
class DocsetBuilder
10
{
11
    protected $docset;
12
13
    protected $grabber;
14
    protected $packager;
15
    protected $archiver;
16
17
    protected $command;
18
19
20 18
    public function __construct(Docset $docset, ?Command $command = null)
21
    {
22 18
        $this->docset = $docset;
23
24 18
        $this->grabber = new DocsetGrabber($this->docset);
25 18
        $this->packager = new DocsetPackager($this->docset);
26 18
        $this->archiver = new DocsetArchiver($this->docset);
27
28 18
        $this->command = $command ?? new LaravelCommand();
29 18
    }
30
31 6
    public function build()
32
    {
33 6
        $this->grab();
34 6
        $this->package();
35 6
        $this->archive();
36 6
    }
37
38 6
    public function grab()
39
    {
40 6
        if (method_exists($this->docset, 'grab')) {
41
            return $this->grabFromDocset();
42
        }
43
44 6
        if ($this->grabber->sitemapExists()) {
45
            return $this->grabFromSitemap();
46
        }
47
48 6
        return $this->grabFromIndex();
49
    }
50
51
    protected function grabFromDocset()
52
    {
53
        return $this->command->task('  - Downloading doc from docset custom instructions', function () {
54
            return $this->docset->grab();
0 ignored issues
show
Bug introduced by
The method grab() does not exist on Godbout\DashDocsetBuilder\Contracts\Docset. ( Ignorable by Annotation )

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

54
            return $this->docset->/** @scrutinizer ignore-call */ grab();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        });
56
    }
57
58
    protected function grabFromSitemap()
59
    {
60
        return $this->command->task('  - Downloading doc from sitemap', function () {
61
            return $this->grabber->grabFromSitemap();
62
        });
63
    }
64
65 6
    protected function grabFromIndex()
66
    {
67
        return $this->command->task('  - Downloading doc from index', function () {
68 6
            return $this->grabber->grabFromIndex();
69 6
        });
70
    }
71
72 12
    public function package()
73
    {
74
        $this->command->task('  - Remove previous .docset', function () {
75 12
            $this->packager->removePreviousDocsetFile();
76 12
        });
77
78
        $this->command->task('  - Create new .docset', function () {
79 12
            return $this->packager->createDocsetFile();
80 12
        });
81
82
        $this->command->task('  - Copy original doc files', function () {
83 12
            return $this->packager->copyDocFiles();
84 12
        });
85
86
        $this->command->task('  - Create Info.plist', function () {
87 12
            return $this->packager->createInfoPlist();
88 12
        });
89
90
        $this->command->task('  - Populate SQLiteIndex', function () {
91 12
            return $this->packager->createAndPopulateSQLiteIndex();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->createAndPopulateSQLiteIndex() targeting Godbout\DashDocsetBuilde...ndPopulateSQLiteIndex() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
92 12
        });
93
94
        $this->command->task('  - Format doc files for Dash', function () {
95 12
            return $this->packager->formatDocFiles();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->formatDocFiles() targeting Godbout\DashDocsetBuilde...kager::formatDocFiles() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
96 12
        });
97
98
        $this->command->task('  - Copy icons', function () {
99 12
            $this->packager->copyIcons();
100 12
        });
101 12
    }
102
103 12
    public function archive()
104
    {
105
        $this->command->task('  - Archiving package', function () {
106 12
            return $this->archiver->archive();
107 12
        });
108 12
    }
109
}
110