Passed
Push — main ( 113815...8a862c )
by Garbuz
02:57
created

DirGenerator::mkdir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage\Builder;
6
7
class DirGenerator
8
{
9
    private Package $package;
10
11
    /**
12
     * @param Package $package
13
     * @return bool
14
     */
15 3
    public function make(Package $package): bool
16
    {
17 3
        $this->package = $package;
18 3
        $this->mkdir($this->package->getPath('config'));
19 3
        $this->mkdir($this->package->getPath('migrations'));
20 3
        $this->mkdir($this->package->getPath('src/Controllers'));
21 3
        $this->mkdir($this->package->getPath('src/Models'));
22 3
        $this->mkdir($this->package->getPath('src/Cases'));
23 3
        $this->makeTests();
24 3
        $this->makeSeeds();
25 3
        $this->makeApi();
26 3
        $this->makeApiFrontend();
27 3
        $this->makeLaravelAdmin();
28 3
        return true;
29
    }
30
31
    /**
32
     * @return bool
33
     */
34 3
    public function makeTests(): bool
35
    {
36 3
        if (!$this->package->getGeneratorTests()) {
37 1
            return false;
38
        }
39 2
        $this->mkdir($this->package->getPath('tests'));
40 2
        return true;
41
    }
42
43
    /**
44
     * @return bool
45
     */
46 3
    public function makeSeeds(): bool
47
    {
48 3
        if (!$this->package->getGeneratorSeed()) {
49 1
            return false;
50
        }
51 2
        $this->mkdir($this->package->getPath('seeds'));
52 2
        return true;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58 3
    public function makeApi(): bool
59
    {
60 3
        if (!$this->package->getGeneratorApi()) {
61 1
            return false;
62
        }
63 2
        $this->mkdir($this->package->getPath('src/Cases/Api'));
64 2
        return true;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70 3
    public function makeApiFrontend(): bool
71
    {
72 3
        if (!$this->package->getGeneratorApiFrontend()) {
73 1
            return false;
74
        }
75 2
        $this->mkdir($this->package->getPath('src/Cases/Api/Frontend'));
76 2
        return true;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82 3
    public function makeLaravelAdmin(): bool
83
    {
84 3
        if (!$this->package->getGeneratorLaravelAdmin()) {
85 1
            return false;
86
        }
87 2
        $this->mkdir($this->package->getPath('src/Admin'));
88 2
        return true;
89
    }
90
91
    /**
92
     * @param string $path
93
     * @return bool
94
     */
95 3
    public function mkdir(string $path): bool
96
    {
97 3
        if (!is_dir($path)) {
98
            mkdir($path, 0777, true);
99
        }
100 3
        return true;
101
    }
102
}
103