Passed
Push — master ( 636760...d1dc62 )
by Guillaume
08:55
created

DocsetNewer::new()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 12
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 21
ccs 0
cts 12
cp 0
crap 6
rs 9.8666
1
<?php
2
3
namespace Godbout\DashDocsetBuilder\Services;
4
5
use Godbout\DashDocsetBuilder\Contracts\Docset;
6
use Illuminate\Support\Facades\Artisan;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\Facades\DB;
9
use Illuminate\Support\Facades\File;
10
use Illuminate\Support\Facades\Storage;
11
use Illuminate\Support\Str;
12
13
final class DocsetNewer
14
{
15
    protected $docsetName;
16
17 18
    public function __construct(?string $docsetName)
18
    {
19 18
        $this->docsetName = $docsetName;
20 18
    }
21
22
    public function new()
23
    {
24
        $userDocsetsDirectory = app_path() . '/../../../../app/Docsets';
25
26
        File::makeDirectory($userDocsetsDirectory, 0755, true, true);
27
28
        if (! $this->docsetName) {
29
            File::copy(
30
                app_path() . '/Services/stubs/RickAstley.stub',
31
                $userDocsetsDirectory . '/RickAstley.php'
32
            );
33
34
            return true;
35
        }
36
37
        File::put(
38
            $userDocsetsDirectory . '/' . Str::studly($this->docsetName) . '.php',
39
            '<?php blah blah blah'
40
        );
41
42
        return true;
43
    }
44
}
45