Passed
Push — master ( c50061...e7f23e )
by Ferry
06:42 queued 02:00
created

Install::handle()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 70
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 35
c 1
b 0
f 0
nc 17
nop 0
dl 0
loc 70
rs 8.7377

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 Illuminate\Support\Facades\DB;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Str;
8
use Symfony\Component\Process\Process;
9
10
class Install extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'crudbooster:install';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'CRUDBooster Installation Command';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function handle()
32
    {
33
34
        $this->header();
35
36
        $this->checkRequirements();
37
38
        $this->info('Installing: ');
39
40
        if ($this->confirm('Do you have setting the database configuration at .env ?')) {
41
42
            if (! file_exists(public_path('vendor')) ) {
43
                mkdir(public_path('vendor'));
44
            }
45
46
            $this->info('Please wait CRUDBooster publish assets...');
47
            $this->call('vendor:publish', ['--tag' => 'cb_config']);
48
            $this->call('vendor:publish', ['--tag' => 'cb_hook']);
49
            $this->call('vendor:publish', ['--tag' => 'cb_asset', '--force' => true]);
50
            $this->call('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]);
51
52
            /*
53
             * Create CBPlugins
54
             */
55
            if(!file_exists(app_path("CBPlugins"))) {
56
                mkdir(app_path("CBPlugins"));
57
            }
58
59
            /*
60
             * Create storage dir on public
61
             * We need it to change default laravel local filesystem from storage to public
62
             * We won't use symlink because of a security issue in many server
63
             */
64
            if(!file_exists(public_path("storage"))) {
65
                $this->info("Create storage directory on /public");
66
                mkdir(public_path("storage"));
67
                file_put_contents(public_path("storage/.gitignore"),"!.gitignore");
68
                file_put_contents(public_path("storage/index.html"),"&nbsp;");
69
            }
70
71
            /*
72
             * We want to add more security to your Laravel
73
             * Disable index listing
74
             * Disable php execution on /vendor/*
75
             */
76
            $this->info("Tweak some security for your laravel");
77
            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);
78
            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);
79
80
81
            $this->info('Dumping the autoloaded files and reloading all new files...');
82
            $composer = $this->findComposer();
83
            $process = new Process($composer.' dump-autoload');
0 ignored issues
show
Bug introduced by
$composer . ' dump-autoload' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
            $process = new Process(/** @scrutinizer ignore-type */ $composer.' dump-autoload');
Loading history...
84
            $process->setWorkingDirectory(base_path())->run();
85
86
            $this->info('Migrating database...');
87
            $this->call('migrate');
88
89
            $this->call('config:clear');
90
            if (app()->version() < 5.6) {
0 ignored issues
show
introduced by
The method version() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
            if (app()->/** @scrutinizer ignore-call */ version() < 5.6) {
Loading history...
91
                $this->call('optimize');
92
            }
93
94
            $this->info('Installing CRUDBooster Is Completed ! Thank You :)');
95
        } else {
96
            $this->info('Setup Aborted !');
97
            $this->info('Please setting the database configuration for first !');
98
        }
99
100
        $this->footer();
101
    }
102
103
    private function header()
104
    {
105
        $this->info("
106
#     __________  __  ______  ____                   __           
107
#    / ____/ __ \/ / / / __ \/ __ )____  ____  _____/ /____  _____
108
#   / /   / /_/ / / / / / / / __  / __ \/ __ \/ ___/ __/ _ \/ ___/
109
#  / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__  ) /_/  __/ /    
110
#  \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/     
111
#                                                                                                                       
112
			");
113
        $this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------');
114
        $this->info('====================================================================');
115
    }
116
117
    private function checkRequirements()
118
    {
119
        $this->info('System Requirements Checking:');
120
        $system_failed = 0;
121
        $laravel = app();
122
123
        if ($laravel::VERSION >= 5.6) {
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...
124
            $this->info('Laravel Version (>= 5.6): [Good]');
125
        } else {
126
            $this->warn('Laravel Version (>= 5.6): [Bad]');
127
            $system_failed++;
128
        }
129
130
        if (version_compare(phpversion(), '7.1.3', '>=')) {
131
            $this->info('PHP Version (>= 7.*): [Good]');
132
        } else {
133
            $this->warn('PHP Version (>= 7.*): [Bad] Yours: '.phpversion());
134
            $system_failed++;
135
        }
136
137
        if (extension_loaded('mbstring')) {
138
            $this->info('Mbstring extension: [Good]');
139
        } else {
140
            $this->warn('Mbstring extension: [Bad]');
141
            $system_failed++;
142
        }
143
144
        if (extension_loaded('openssl')) {
145
            $this->info('OpenSSL extension: [Good]');
146
        } else {
147
            $this->warn('OpenSSL extension: [Bad]');
148
            $system_failed++;
149
        }
150
151
        if (extension_loaded('pdo')) {
152
            $this->info('PDO extension: [Good]');
153
        } else {
154
            $this->warn('PDO extension: [Bad]');
155
            $system_failed++;
156
        }
157
158
        if (extension_loaded('tokenizer')) {
159
            $this->info('Tokenizer extension: [Good]');
160
        } else {
161
            $this->warn('Tokenizer extension: [Bad]');
162
            $system_failed++;
163
        }
164
165
        if (extension_loaded('xml')) {
166
            $this->info('XML extension: [Good]');
167
        } else {
168
            $this->warn('XML extension: [Bad]');
169
            $system_failed++;
170
        }
171
172
        if (extension_loaded('gd')) {
173
            $this->info('GD extension: [Good]');
174
        } else {
175
            $this->warn('GD extension: [Bad]');
176
            $system_failed++;
177
        }
178
179
        if (extension_loaded('fileinfo')) {
180
            $this->info('PHP Fileinfo extension: [Good]');
181
        } else {
182
            $this->warn('PHP Fileinfo extension: [Bad]');
183
            $system_failed++;
184
        }
185
186
        if (is_writable(base_path('public'))) {
187
            $this->info('public dir is writable: [Good]');
188
        } else {
189
            $this->warn('public dir is writable: [Bad]');
190
            $system_failed++;
191
        }
192
193
        if ($system_failed != 0) {
194
            $this->warn('Sorry unfortunately your system is not meet with our requirements !');
195
            $this->footer(false);
196
        }
197
        $this->info('--');
198
    }
199
200
    private function footer($success = true)
201
    {
202
203
        $this->info('--');
204
205
        (new DeveloperCommandService($this))->create();
206
207
        $this->info("--");
208
        $this->info('Homepage : http://crudbooster.com');
209
        $this->info('Github : https://github.com/crocodic-studio/crudbooster');
210
        $this->info('====================================================================');
211
        if ($success == true) {
212
            $this->info('------------------- :===: Completed !! :===: ------------------------');
213
        } else {
214
            $this->info('------------------- :===: Failed !!    :===: ------------------------');
215
        }
216
        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...
217
    }
218
219
    /**
220
     * Get the composer command for the environment.
221
     *
222
     * @return string
223
     */
224
    protected function findComposer()
225
    {
226
        if (file_exists(getcwd().'/composer.phar')) {
227
            return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
228
        }
229
230
        return 'composer';
231
    }
232
}
233