GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch develop (32836c)
by milkmeowo
02:59
created

BaseInitCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * BaseInitCommand.php.
4
 *
5
 * Description
6
 *
7
 * @author Milkmeowo <[email protected]>
8
 */
9
10
namespace Milkmeowo\Framework\Repository\Generators\Commands;
11
12
use Illuminate\Console\Command;
13
use Illuminate\Filesystem\Filesystem;
14
use Milkmeowo\Framework\Repository\Generators\ModelGenerator;
15
use Milkmeowo\Framework\Repository\Generators\PresenterGenerator;
16
use Milkmeowo\Framework\Repository\Generators\ControllerGenerator;
17
use Milkmeowo\Framework\Repository\Generators\TransformerGenerator;
18
use Milkmeowo\Framework\Repository\Generators\RepositoryEloquentGenerator;
19
use Milkmeowo\Framework\Repository\Generators\RepositoryInterfaceGenerator;
20
21
class BaseInitCommand extends Command
22
{
23
    /**
24
     * The name and signature of the console command.
25
     *
26
     * @var string
27
     */
28
    protected $signature = 'starter:base';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Create starter base files';
36
37
    /**
38
     * The Filesystem instance.
39
     *
40
     * @var Filesystem
41
     */
42
    protected $filesystem;
43
44
    /**
45
     * Filename of stub-file.
46
     *
47
     * @var string
48
     */
49
    protected $stubs = [
50
        'api.controller.laravel'  => 'Api/LaravelBaseController',
51
        'api.controller.lumen'    => 'Api/LumenBaseController',
52
        'http.controller.laravel' => 'Http/LaravelBaseController',
53
        'http.controller.lumen'   => 'Http/LumenBaseController',
54
        'model'                   => 'Models/BaseModel',
55
        'presenter'               => 'Presenters/BasePresenter',
56
        'repositories.eloquent'   => 'Repositories/Eloquent/BaseRepository',
57
        'repositories.interfaces' => 'Repositories/Interfaces/BaseRepositoryInterface',
58
        'transformer' => 'Transformers/BaseTransformer',
59
    ];
60
61
    /**
62
     * BaseInitCommand constructor.
63
     *
64
     * @param Filesystem $filesystem
65
     */
66
    public function __construct(Filesystem $filesystem)
67
    {
68
        $this->filesystem = $filesystem;
69
70
        parent::__construct();
71
    }
72
73
    public function handle()
74
    {
75
        $this->generateApiController();
76
77
        $this->generateHttpController();
78
79
        $this->generateModel();
80
81
        $this->generateRepositoriesEloquent();
82
83
        $this->generateRepositoriesInterfaces();
84
85
        $this->generatePresenters();
86
87
        $this->generateTransformer();
88
    }
89
90 View Code Duplication
    public function generateApiController()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $stub = is_lumen() ? $this->stubs['api.controller.lumen'] : $this->stubs['api.controller.laravel'];
93
        $stub = $this->getStub($stub);
94
95
        $controllerGenerator = new ControllerGenerator(['name' => 'Base']);
96
        $namespace = $controllerGenerator->getNamespace();
97
98
        $path = $controllerGenerator->getBasePath().'/'.$controllerGenerator->getConfigGeneratorClassPath($controllerGenerator->getPathConfigNode(),
99
                true).'/BaseController.php';
100
101
        $this->generateFile($path, $stub, $namespace);
102
    }
103
104
    public function generateHttpController()
105
    {
106
        $stub = is_lumen() ? $this->stubs['http.controller.lumen'] : $this->stubs['http.controller.laravel'];
107
        $stub = $this->getStub($stub);
108
        $path = app()->path().'/Http/Controllers/BaseController.php';
109
        $namespace = 'namespace '.app()->getNamespace().'Http\Controllers;';
110
111
        $this->generateFile($path, $stub, $namespace);
112
    }
113
114 View Code Duplication
    public function generateModel()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
    {
116
        $stub = $this->stubs['model'];
117
        $stub = $this->getStub($stub);
118
        $generator = new ModelGenerator(['name' => 'BaseModel']);
119
        $namespace = $generator->getNamespace();
120
        $path = $generator->getPath();
121
122
        $this->generateFile($path, $stub, $namespace);
123
    }
124
125 View Code Duplication
    public function generatePresenters()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127
        $stub = $this->stubs['presenter'];
128
        $stub = $this->getStub($stub);
129
        $generator = new PresenterGenerator(['name' => 'Base']);
130
        $namespace = $generator->getNamespace();
131
        $path = $generator->getPath();
132
133
        $this->generateFile($path, $stub, $namespace);
134
    }
135
136 View Code Duplication
    public function generateRepositoriesEloquent()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138
        $stub = $this->stubs['repositories.eloquent'];
139
        $stub = $this->getStub($stub);
140
        $generator = new RepositoryEloquentGenerator(['name' => 'Base']);
141
        $namespace = $generator->getNamespace();
142
        $path = $generator->getBasePath().'/'.$generator->getConfigGeneratorClassPath($generator->getPathConfigNode(),
143
                true).'/BaseRepository.php';
144
145
        $this->generateFile($path, $stub, $namespace);
146
    }
147
148 View Code Duplication
    public function generateRepositoriesInterfaces()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        $stub = $this->stubs['repositories.interfaces'];
151
        $stub = $this->getStub($stub);
152
        $generator = new RepositoryInterfaceGenerator(['name' => 'Base']);
153
        $namespace = $generator->getNamespace();
154
        $path = $generator->getBasePath().'/'.$generator->getConfigGeneratorClassPath($generator->getPathConfigNode(),
155
                true).'/BaseRepositoryInterface.php';
156
157
        $this->generateFile($path, $stub, $namespace);
158
    }
159
160 View Code Duplication
    public function generateTransformer()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
    {
162
        $stub = $this->stubs['transformer'];
163
        $stub = $this->getStub($stub);
164
        $generator = new TransformerGenerator(['name' => 'Base']);
165
        $namespace = $generator->getNamespace();
166
        $path = $generator->getPath();
167
168
        $this->generateFile($path, $stub, $namespace);
169
    }
170
171
    public function generateFile($path, $stub, $namespace)
172
    {
173
        if (! $this->filesystem->exists($path) || $this->confirm($path.' already exists! Continue?')) {
174
            $content = str_replace('$NAMESPACE$', $namespace, $stub);
175
176 View Code Duplication
            if (! $this->filesystem->isDirectory($dir = dirname($path))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
                $this->filesystem->makeDirectory($dir, 0777, true, true);
178
            }
179
180
            $this->filesystem->put($path, $content);
181
            $this->line('---------------');
182
            $this->info($path.' generated');
183
            $this->line('---------------');
184
        }
185
    }
186
187
    public function getPath($stub)
188
    {
189
        $defaultPath = dirname(__DIR__);
190
        $path = config('repository.generator.stubsOverridePath', $defaultPath);
191
192
        // rollback
193
        if (! file_exists($path.'/Stubs/base/'.$stub.'.stub')) {
194
            $path = $defaultPath;
195
        }
196
197
        return $path.'/Stubs/base/'.$stub.'.stub';
198
    }
199
200
    public function getStub($stub)
201
    {
202
        return $this->filesystem->get($this->getPath($stub));
203
    }
204
}
205