Passed
Push — analysis-XNGW1g ( 55039c )
by Kyle
07:59 queued 32s
created

BaseGenerator::getViewPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands\Generator;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Str;
8
9
abstract class BaseGenerator extends Command
10
{
11
    protected $filesystem;
12
13
    /**
14
     * Create a new command instance.
15
     *
16
     * @return void
17
     */
18
    public function __construct(Filesystem $filesystem)
19
    {
20
        parent::__construct();
21
22
        $this->filesystem = $filesystem;
23
    }
24
25
    /**
26
     * get stub content.
27
     *
28
     * @param $type
29
     *
30
     * @return bool|string
31
     */
32
    protected function getStubs($type) : string
33
    {
34
        return $this->filesystem->get(__DIR__."/stubs/$type.stub");
35
    }
36
37
    /**
38
     * Get path for save controller files.
39
     *
40
     * @return string
41
     */
42
    protected function getControllerPath() : string
43
    {
44
        return app_path('Http/Controllers/Admin/');
45
    }
46
47
    /**
48
     * Get path for save View files.
49
     *
50
     * @return string
51
     */
52
    protected function getViewPath() : string
53
    {
54
        return resource_path('views/admin/');
55
    }
56
57
    /**
58
     * Get path for save Repository files.
59
     *
60
     * @return string
61
     */
62
    protected function getRepositoriesPath() : string
63
    {
64
        return app_path('Repositories/');
65
    }
66
67
    /**
68
     * Get path for update Repository files.
69
     *
70
     * @return string
71
     */
72
    protected function getBindServiceProviderPath() : string
73
    {
74
        return app_path('Providers/AppServiceProvider.php');
75
    }
76
77
    /**
78
     * Get path for save Services files.
79
     *
80
     * @return string
81
     */
82
    protected function getServicesPath() : string
83
    {
84
        return app_path('Services/');
85
    }
86
87
    /**
88
     * Get target name.
89
     *
90
     * @return array|null|string
91
     */
92
    protected function getTargetName()
93
    {
94
        return $this->argument('name');
95
    }
96
97
    /**
98
     * Replace & save file.
99
     *
100
     * @param $stub
101
     * @param $path
102
     * @param $name
103
     */
104
    protected function proceedAndSaveFile($name, $stub, $path)
105
    {
106
        $template = str_replace([
107
            '{{Model}}',
108
            '{{model}}',
109
            '{{models}}',
110
        ], [
111
            ucwords($name),
112
            strtolower($name),
113
            strtolower(Str::plural($name)),
114
        ],
115
            $this->getStubs($stub)
116
        );
117
        $this->filesystem->put($path, $template);
118
    }
119
}
120