Completed
Pull Request — master (#163)
by
unknown
08:39
created

InstallCommand::createBootstrapFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Commands;
4
5
use Encore\Admin\Facades\Admin;
6
use Illuminate\Console\Command;
7
8
class InstallCommand extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'admin:install';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Install the admin package';
23
24
    /**
25
     * Install directory.
26
     *
27
     * @var string
28
     */
29
    protected $directory = '';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return void
35
     */
36
    public function fire()
37
    {
38
        $this->publishDatabase();
39
40
        $this->initAdminDirectory();
41
    }
42
43
    /**
44
     * Create tables and seed it.
45
     *
46
     * @return void
47
     */
48
    public function publishDatabase()
49
    {
50
        $this->call('migrate', ['--path' => str_replace(base_path(), '', __DIR__).'/../../migrations/']);
51
52
        $this->call('db:seed', ['--class' => \Encore\Admin\Auth\Database\AdminTablesSeeder::class]);
53
    }
54
55
    /**
56
     * Initialize the admin directory.
57
     *
58
     * @return void
59
     */
60
    protected function initAdminDirectory()
61
    {
62
        $this->directory = config('admin.directory');
63
64
        if (is_dir($this->directory)) {
65
            $this->line("<error>{$this->directory} directory already exists !</error> ");
66
67
            return;
68
        }
69
70
        $this->makeDir('/');
71
        $this->line('<info>Admin directory was created:</info> '.str_replace(base_path(), '', $this->directory));
72
73
        $this->makeDir('Controllers');
74
75
        $this->createHomeController();
76
        $this->createExampleController();
77
        //$this->createAuthController();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
        //$this->createAdministratorController();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
80
        //$this->createMenuFile();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
        $this->createBootstrapFile();
82
        $this->createRoutesFile();
83
84
        //$this->copyLanguageFiles();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
85
    }
86
87
    /**
88
     * Create HomeController.
89
     *
90
     * @return void
91
     */
92 View Code Duplication
    public function createHomeController()
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...
93
    {
94
        $homeController = $this->directory.'/Controllers/HomeController.php';
95
        $contents = $this->getStub('HomeController');
96
97
        $this->laravel['files']->put(
98
            $homeController,
99
            str_replace('DummyNamespace', Admin::controllerNamespace(), $contents)
100
        );
101
        $this->line('<info>HomeController file was created:</info> '.str_replace(base_path(), '', $homeController));
102
    }
103
104
    /**
105
     * Create HomeController.
106
     *
107
     * @return void
108
     */
109 View Code Duplication
    public function createExampleController()
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...
110
    {
111
        $exampleController = $this->directory.'/Controllers/ExampleController.php';
112
        $contents = $this->getStub('ExampleController');
113
114
        $this->laravel['files']->put(
115
            $exampleController,
116
            str_replace('DummyNamespace', Admin::controllerNamespace(), $contents)
117
        );
118
        $this->line('<info>ExampleController file was created:</info> '.str_replace(base_path(), '', $exampleController));
119
    }
120
121
    /**
122
     * Create AuthController.
123
     *
124
     * @return void
125
     */
126 View Code Duplication
    public function createAuthController()
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...
127
    {
128
        $authController = $this->directory.'/Controllers/AuthController.php';
129
        $contents = $this->getStub('AuthController');
130
131
        $this->laravel['files']->put(
132
            $authController,
133
            str_replace('DummyNamespace', Admin::controllerNamespace(), $contents)
134
        );
135
        $this->line('<info>AuthController file was created:</info> '.str_replace(base_path(), '', $authController));
136
    }
137
138
    /**
139
     * Create AdministratorController.
140
     *
141
     * @return void
142
     */
143 View Code Duplication
    public function createAdministratorController()
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...
144
    {
145
        $controller = $this->directory.'/Controllers/AdministratorController.php';
146
        $contents = $this->getStub('AdministratorController');
147
148
        $this->laravel['files']->put(
149
            $controller,
150
            str_replace('DummyNamespace', Admin::controllerNamespace(), $contents)
151
        );
152
        $this->line(
153
            '<info>AdministratorController file was created:</info> '.str_replace(base_path(), '', $controller)
154
        );
155
    }
156
157
    /**
158
     * Create menu file.
159
     *
160
     * @return void
161
     */
162 View Code Duplication
    protected function createMenuFile()
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...
163
    {
164
        $file = $this->directory.'/menu.php';
165
166
        $contents = $this->getStub('menu');
167
        $this->laravel['files']->put($file, $contents);
168
        $this->line('<info>Menu file was created:</info> '.str_replace(base_path(), '', $file));
169
    }
170
171
    /**
172
     * Create routes file.
173
     *
174
     * @return void
175
     */
176 View Code Duplication
    protected function createBootstrapFile()
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...
177
    {
178
        $file = $this->directory.'/bootstrap.php';
179
180
        $contents = $this->getStub('bootstrap');
181
        $this->laravel['files']->put($file, $contents);
182
        $this->line('<info>Bootstrap file was created:</info> '.str_replace(base_path(), '', $file));
183
    }
184
185
    /**
186
     * Create routes file.
187
     *
188
     * @return void
189
     */
190
    protected function createRoutesFile()
191
    {
192
        $file = $this->directory.'/routes.php';
193
194
        $contents = $this->getStub('routes');
195
        $this->laravel['files']->put($file, str_replace('DummyNamespace', Admin::controllerNamespace(), $contents));
196
        $this->line('<info>Routes file was created:</info> '.str_replace(base_path(), '', $file));
197
    }
198
199
    /**
200
     * Copy language files to admin directory.
201
     *
202
     * @return void
203
     */
204
    protected function copyLanguageFiles()
205
    {
206
        $this->laravel['files']->copyDirectory(__DIR__.'/../../lang/', "{$this->directory}/lang/");
207
    }
208
209
    /**
210
     * Get stub contents.
211
     *
212
     * @param $name
213
     *
214
     * @return string
215
     */
216
    protected function getStub($name)
217
    {
218
        return $this->laravel['files']->get(__DIR__."/stubs/$name.stub");
219
    }
220
221
    /**
222
     * Make new directory.
223
     *
224
     * @param string $path
225
     */
226
    protected function makeDir($path = '')
227
    {
228
        $this->laravel['files']->makeDirectory("{$this->directory}/$path", 0755, true, true);
229
    }
230
}
231