Passed
Push — master ( 2cb055...b2403f )
by Ferry
04:01
created

Install::handle()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 70
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 33
c 2
b 0
f 0
nc 9
nop 0
dl 0
loc 70
rs 9.0808

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace crocodicstudio\crudbooster\commands;
2
3
use App;
4
use Cache;
5
use crocodicstudio\crudbooster\helpers\ComposerHelper;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Str;
9
use Symfony\Component\Process\Process;
10
11
class Install extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'crudbooster:install';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'CRUDBooster Installation Command';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return mixed
31
     */
32
    public function handle()
33
    {
34
35
        $this->header();
36
37
        $this->checkRequirements();
38
39
        $this->info('Installing: ');
40
41
        if ($this->confirm('Do you have setting the database configuration at .env ?')) {
42
43
            if (! file_exists(public_path('vendor')) ) {
44
                mkdir(public_path('vendor'));
45
            }
46
47
            $this->info('Please wait CRUDBooster publish assets...');
48
            $this->call('vendor:publish', ['--tag' => 'cb_config']);
49
            $this->call('vendor:publish', ['--tag' => 'cb_hook']);
50
            $this->call('vendor:publish', ['--tag' => 'cb_asset', '--force' => true]);
51
            $this->call('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]);
52
53
            /*
54
             * Add some env for CB
55
             */
56
            setEnvironmentValue([
57
                "APP_DEBUG"=> false
58
            ]);
59
60
            /*
61
             * Create CBPlugins
62
             */
63
            if(!file_exists(app_path("CBPlugins"))) {
64
                mkdir(app_path("CBPlugins"));
65
            }
66
67
            /*
68
             * Create storage dir on public
69
             * We need it to change default laravel local filesystem from storage to public
70
             * We won't use symlink because of a security issue in many server
71
             */
72
            if(!file_exists(public_path("storage"))) {
73
                $this->info("Create storage directory on /public");
74
                mkdir(public_path("storage"));
75
                file_put_contents(public_path("storage/.gitignore"),"!.gitignore");
76
                file_put_contents(public_path("storage/index.html"),"&nbsp;");
77
            }
78
79
            /*
80
             * We want to add more security to your Laravel
81
             * Disable index listing
82
             * Disable php execution on /vendor/*
83
             */
84
            $this->info("Tweak some security for your laravel");
85
            file_put_contents(base_path(".htaccess"), "\n\n# Generated by CRUDBooster\nServerSignature Off\nIndexIgnore *\nRewriteRule ^(.*)/vendor/.*\.(php|rb|py)$ - [F,L,NC]\nRewriteRule ^vendor/.*\.(php|rb|py)$ - [F,L,NC]\n<FilesMatch \"^\.\">\nOrder allow,deny\nDeny from all\n</FilesMatch>",FILE_APPEND);
86
            file_put_contents(public_path(".htaccess"), "\n\n# Generated by CRUDBooster\nServerSignature Off\nIndexIgnore *\nRewriteRule ^(.*)/vendor/.*\.(php|rb|py)$ - [F,L,NC]\nRewriteRule ^vendor/.*\.(php|rb|py)$ - [F,L,NC]\n<FilesMatch \"^\.\">\nOrder allow,deny\nDeny from all\n</FilesMatch>",FILE_APPEND);
87
88
89
            $this->info('Dumping the autoloaded files and reloading all new files...');
90
            ComposerHelper::dumpAutoLoad();
91
92
            $this->info('Migrating database...');
93
            $this->call('migrate');
94
            $this->call('config:clear');
95
            $this->info('Installing CRUDBooster Is Completed ! Thank You :)');
96
        } else {
97
            $this->info('Setup Aborted !');
98
            $this->info('Please setting the database configuration for first !');
99
        }
100
101
        $this->footer();
102
    }
103
104
    private function header()
105
    {
106
        $this->info("
107
#     __________  __  ______  ____                   __           
108
#    / ____/ __ \/ / / / __ \/ __ )____  ____  _____/ /____  _____
109
#   / /   / /_/ / / / / / / / __  / __ \/ __ \/ ___/ __/ _ \/ ___/
110
#  / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__  ) /_/  __/ /    
111
#  \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/     
112
#                                                                                                                       
113
			");
114
        $this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------');
115
        $this->info('====================================================================');
116
    }
117
118
    private function checkRequirements()
119
    {
120
        $this->info('System Requirements Checking:');
121
        $system_failed = 0;
122
        $laravel = app();
123
124
        if ($laravel::VERSION >= 5.7) {
0 ignored issues
show
Bug introduced by
The constant Illuminate\Container\Container::VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
125
            $this->info('Laravel Version (>= 5.7): [Good]');
126
        } else {
127
            $this->warn('Laravel Version (>= 5.7): [Bad]');
128
            $system_failed++;
129
        }
130
131
        if (version_compare(phpversion(), '7.2.0', '>=')) {
132
            $this->info('PHP Version (>= 7.2.0): [Good]');
133
        } else {
134
            $this->warn('PHP Version (>= 7.2.0): [Bad] Yours: '.phpversion());
135
            $system_failed++;
136
        }
137
138
        if (extension_loaded('mbstring')) {
139
            $this->info('Mbstring extension: [Good]');
140
        } else {
141
            $this->warn('Mbstring extension: [Bad]');
142
            $system_failed++;
143
        }
144
145
        if (extension_loaded('openssl')) {
146
            $this->info('OpenSSL extension: [Good]');
147
        } else {
148
            $this->warn('OpenSSL extension: [Bad]');
149
            $system_failed++;
150
        }
151
152
        if (extension_loaded('pdo')) {
153
            $this->info('PDO extension: [Good]');
154
        } else {
155
            $this->warn('PDO extension: [Bad]');
156
            $system_failed++;
157
        }
158
159
        if (extension_loaded('tokenizer')) {
160
            $this->info('Tokenizer extension: [Good]');
161
        } else {
162
            $this->warn('Tokenizer extension: [Bad]');
163
            $system_failed++;
164
        }
165
166
        if (extension_loaded('xml')) {
167
            $this->info('XML extension: [Good]');
168
        } else {
169
            $this->warn('XML extension: [Bad]');
170
            $system_failed++;
171
        }
172
173
        if (extension_loaded('gd')) {
174
            $this->info('GD extension: [Good]');
175
        } else {
176
            $this->warn('GD extension: [Bad]');
177
            $system_failed++;
178
        }
179
180
        if (extension_loaded('fileinfo')) {
181
            $this->info('PHP Fileinfo extension: [Good]');
182
        } else {
183
            $this->warn('PHP Fileinfo extension: [Bad]');
184
            $system_failed++;
185
        }
186
187
        if (is_writable(base_path('public'))) {
188
            $this->info('public dir is writable: [Good]');
189
        } else {
190
            $this->warn('public dir is writable: [Bad]');
191
            $system_failed++;
192
        }
193
194
        if ($system_failed != 0) {
195
            $this->warn('Sorry unfortunately your system is not meet with our requirements !');
196
            $this->footer(false);
197
        }
198
        $this->info('--');
199
    }
200
201
    private function footer($success = true)
202
    {
203
204
        $this->info('--');
205
206
        (new DeveloperCommandService($this))->create();
207
208
        $this->info("--");
209
        $this->info('Homepage : http://crudbooster.com');
210
        $this->info('Github : https://github.com/crocodic-studio/crudbooster');
211
        $this->info('====================================================================');
212
        if ($success == true) {
213
            $this->info('------------------- :===: Completed !! :===: ------------------------');
214
        } else {
215
            $this->info('------------------- :===: Failed !!    :===: ------------------------');
216
        }
217
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
218
    }
219
220
}
221