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

DocsetNewer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A new() 0 28 3
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