Passed
Push — master ( d1dc62...a1972e )
by Guillaume
08:28
created

DocsetNewer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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