Passed
Push — master ( 1476e6...379d7e )
by Guillaume
02:28
created

DocsetBuilder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 8
eloc 37
dl 0
loc 87
ccs 25
cts 40
cp 0.625
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A grab() 0 7 2
A __construct() 0 9 1
A build() 0 5 1
A grabFromSitemap() 0 4 1
A package() 0 28 1
A grabFromIndex() 0 4 1
A archive() 0 4 1
1
<?php
2
3
namespace App\Services;
4
5
use App\Contracts\Docset;
6
use LaravelZero\Framework\Commands\Command;
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 25
    public function __construct(Docset $docset, ?Command $command = null)
21
    {
22 25
        $this->docset = $docset;
23
24 25
        $this->grabber = new DocsetGrabber($this->docset);
25 25
        $this->packager = new DocsetPackager($this->docset);
26 25
        $this->archiver = new DocsetArchiver($this->docset);
27
28 25
        $this->command = $command ?? new LaravelCommand();
29 25
    }
30
31
    public function build()
32
    {
33
        $this->grab();
34
        $this->package();
35
        $this->archive();
36
    }
37
38
    public function grab()
39
    {
40
        if ($this->grabber->sitemapExists()) {
41
            return $this->grabFromSitemap();
42
        }
43
44
        return $this->grabFromIndex();
45
    }
46
47
    protected function grabFromSitemap()
48
    {
49
        return $this->command->task('  - Downloading doc from sitemap', function () {
50
            return $this->grabber->grabFromSitemap();
51
        });
52
    }
53
54
    protected function grabFromIndex()
55
    {
56
        return $this->command->task('  - Downloading doc from index', function () {
57
            return $this->grabber->grabFromIndex();
58
        });
59
    }
60
61 1
    public function package()
62
    {
63
        $this->command->task('  - Remove previous .docset', function () {
64 1
            return $this->packager->removePreviousDocsetFile();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->removePreviousDocsetFile() targeting App\Services\DocsetPacka...ovePreviousDocsetFile() 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...
65 1
        });
66
67
        $this->command->task('  - Create new .docset', function () {
68 1
            return $this->packager->createDocsetFile();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->createDocsetFile() targeting App\Services\DocsetPackager::createDocsetFile() 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...
69 1
        });
70
71
        $this->command->task('  - Copy original doc files', function () {
72 1
            return $this->packager->copyDocFiles();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->copyDocFiles() targeting App\Services\DocsetPackager::copyDocFiles() 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...
73 1
        });
74
75
        $this->command->task('  - Create Info.plist', function () {
76 1
            return $this->packager->createInfoPlist();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->createInfoPlist() targeting App\Services\DocsetPackager::createInfoPlist() 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...
77 1
        });
78
79
        $this->command->task('  - Populate SQLiteIndex', function () {
80 1
            return $this->packager->createAndPopulateSQLiteIndex();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->createAndPopulateSQLiteIndex() targeting App\Services\DocsetPacka...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...
81 1
        });
82
83
        $this->command->task('  - Format doc files for Dash', function () {
84 1
            return $this->packager->formatDocFiles();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->formatDocFiles() targeting App\Services\DocsetPackager::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...
85 1
        });
86
87
        $this->command->task('  - Copy icons', function () {
88 1
            return $this->packager->copyIcons();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->packager->copyIcons() targeting App\Services\DocsetPackager::copyIcons() 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...
89 1
        });
90 1
    }
91
92 1
    public function archive()
93
    {
94
        $this->command->task('  - Archiving package', function () {
95 1
            return $this->archiver->archive();
96 1
        });
97 1
    }
98
}
99