godbout /
dash-docset-builder
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Godbout\DashDocsetBuilder\Services; |
||||||
| 4 | |||||||
| 5 | use Godbout\DashDocsetBuilder\Contracts\Docset; |
||||||
| 6 | use Illuminate\Console\Command as LaravelCommand; |
||||||
| 7 | use Illuminate\Support\Str; |
||||||
| 8 | use LaravelZero\Framework\Commands\Command; |
||||||
| 9 | |||||||
| 10 | class DocsetBuilder |
||||||
| 11 | { |
||||||
| 12 | protected $docset; |
||||||
| 13 | |||||||
| 14 | protected $newer; |
||||||
| 15 | protected $grabber; |
||||||
| 16 | protected $packager; |
||||||
| 17 | protected $archiver; |
||||||
| 18 | |||||||
| 19 | protected $command; |
||||||
| 20 | |||||||
| 21 | |||||||
| 22 | 56 | public function __construct(?Docset $docset = null, ?Command $command = null) |
|||||
| 23 | { |
||||||
| 24 | 56 | $this->docset = $docset; |
|||||
| 25 | 56 | $this->command = $command ?? new LaravelCommand(); |
|||||
| 26 | |||||||
| 27 | 56 | $this->newer = new DocsetNewer(); |
|||||
| 28 | |||||||
| 29 | 56 | if ($this->docset) { |
|||||
| 30 | 24 | $this->grabber = new DocsetGrabber($this->docset); |
|||||
| 31 | 24 | $this->packager = new DocsetPackager($this->docset); |
|||||
| 32 | 24 | $this->archiver = new DocsetArchiver($this->docset); |
|||||
| 33 | } |
||||||
| 34 | 56 | } |
|||||
| 35 | |||||||
| 36 | 32 | public function new() |
|||||
| 37 | { |
||||||
| 38 | 32 | $newDocset = $this->command->argument('doc'); |
|||||
| 39 | |||||||
| 40 | 32 | if (! $newDocset) { |
|||||
| 41 | 16 | return $this->command->task(' - Never gonna give you up. Generating app/Docsets/RickAstley.php', function () { |
|||||
| 42 | 16 | $this->newer->new(); |
|||||
| 43 | 16 | }); |
|||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | 24 | return $this->command->task(' - Generating app/Docsets/' . Str::studly($newDocset) . '.php', function () use ($newDocset) { |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 47 | 24 | $this->newer->new($newDocset); |
|||||
|
0 ignored issues
–
show
It seems like
$newDocset can also be of type array; however, parameter $newDocset of Godbout\DashDocsetBuilde...ices\DocsetNewer::new() does only seem to accept null|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | 24 | }); |
|||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | 8 | public function build() |
|||||
| 52 | { |
||||||
| 53 | 8 | $this->grab(); |
|||||
| 54 | 8 | $this->package(); |
|||||
| 55 | 8 | $this->archive(); |
|||||
| 56 | 8 | } |
|||||
| 57 | |||||||
| 58 | 8 | public function grab() |
|||||
| 59 | { |
||||||
| 60 | 8 | if (method_exists($this->docset, 'grab')) { |
|||||
| 61 | return $this->grabFromDocset(); |
||||||
| 62 | } |
||||||
| 63 | |||||||
| 64 | 8 | if ($this->grabber->sitemapExists()) { |
|||||
| 65 | return $this->grabFromSitemap(); |
||||||
| 66 | } |
||||||
| 67 | |||||||
| 68 | 8 | return $this->grabFromIndex(); |
|||||
| 69 | } |
||||||
| 70 | |||||||
| 71 | protected function grabFromDocset() |
||||||
| 72 | { |
||||||
| 73 | return $this->command->task(' - Downloading doc from docset custom instructions', function () { |
||||||
| 74 | return $this->docset->grab(); |
||||||
|
0 ignored issues
–
show
The method
grab() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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...
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
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...
|
|||||||
| 75 | }); |
||||||
| 76 | } |
||||||
| 77 | |||||||
| 78 | protected function grabFromSitemap() |
||||||
| 79 | { |
||||||
| 80 | return $this->command->task(' - Downloading doc from sitemap', function () { |
||||||
| 81 | return $this->grabber->grabFromSitemap(); |
||||||
| 82 | }); |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | 8 | protected function grabFromIndex() |
|||||
| 86 | { |
||||||
| 87 | 8 | return $this->command->task(' - Downloading doc from index', function () { |
|||||
| 88 | 8 | return $this->grabber->grabFromIndex(); |
|||||
| 89 | 8 | }); |
|||||
| 90 | } |
||||||
| 91 | |||||||
| 92 | 16 | public function package() |
|||||
| 93 | { |
||||||
| 94 | 16 | $this->command->task(' - Remove previous .docset', function () { |
|||||
| 95 | 16 | $this->packager->removePreviousDocsetFile(); |
|||||
| 96 | 16 | }); |
|||||
| 97 | |||||||
| 98 | 16 | $this->command->task(' - Create new .docset', function () { |
|||||
| 99 | 16 | return $this->packager->createDocsetFile(); |
|||||
| 100 | 16 | }); |
|||||
| 101 | |||||||
| 102 | 16 | $this->command->task(' - Copy original doc files', function () { |
|||||
| 103 | 16 | return $this->packager->copyDocFiles(); |
|||||
| 104 | 16 | }); |
|||||
| 105 | |||||||
| 106 | 16 | $this->command->task(' - Create Info.plist', function () { |
|||||
| 107 | 16 | return $this->packager->createInfoPlist(); |
|||||
| 108 | 16 | }); |
|||||
| 109 | |||||||
| 110 | 16 | $this->command->task(' - Populate SQLiteIndex', function () { |
|||||
| 111 | 16 | return $this->packager->createAndPopulateSQLiteIndex(); |
|||||
| 112 | 16 | }); |
|||||
| 113 | |||||||
| 114 | 16 | $this->command->task(' - Format doc files for Dash', function () { |
|||||
| 115 | 16 | return $this->packager->formatDocFiles(); |
|||||
| 116 | 16 | }); |
|||||
| 117 | |||||||
| 118 | 16 | $this->command->task(' - Copy icons', function () { |
|||||
| 119 | 16 | $this->packager->copyIcons(); |
|||||
| 120 | 16 | }); |
|||||
| 121 | 16 | } |
|||||
| 122 | |||||||
| 123 | 16 | public function archive() |
|||||
| 124 | { |
||||||
| 125 | 16 | $this->command->task(' - Archiving package', function () { |
|||||
| 126 | 16 | return $this->archiver->archive(); |
|||||
| 127 | 16 | }); |
|||||
| 128 | 16 | } |
|||||
| 129 | } |
||||||
| 130 |