Passed
Pull Request — master (#1095)
by Iman
03:10
created

checkRequirements()   F

Complexity

Conditions 12
Paths 2048

Size

Total Lines 81
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 57
nc 2048
nop 0
dl 0
loc 81
c 0
b 0
f 0
cc 12
rs 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A CrudboosterInstallationCommand::findComposer() 0 7 2
A CrudboosterInstallationCommand::symlinkForUpload() 0 14 3
A CrudboosterInstallationCommand::symlinkForAsset() 0 19 3
A CrudboosterInstallationCommand::removeDefaultMigrations() 0 5 1

How to fix   Long Method    Complexity   

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 Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Illuminate\Foundation\Inspiring;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Inspiring was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Process\Process;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Process\Process was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use DB;
9
use Cache;
10
use Request;
11
use CRUDBooster;
0 ignored issues
show
Bug introduced by
The type CRUDBooster was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use App;
13
14
class CrudboosterInstallationCommand extends Command
15
{
16
    /**
17
     * The console command name.
18
     *
19
     * @var string
20
     */
21
    protected $name = 'crudbooster:install';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'CRUDBooster Installation Command';
29
30
    /**
31
     * Execute the console command.
32
     *
33
     * @return mixed
34
     */
35
    public function handle()
36
    {
37
38
        $this->printHeader();
39
40
        $passes = (new RequirementChecker())->check();
41
        if(!$passes) {
42
            $this->info('Sorry unfortunately your system is not meet with our requirements !');
43
            $this->printFooter(false);
44
            $this->info('--');
45
            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...
46
        }
47
48
        $this->info('Installing: ');
49
        /* Removing the default user and password reset, it makes you ambigous when using CRUDBooster */
50
        $this->removeDefaultMigrations();
51
52
        //Create vendor folder at public
53
        $this->createVendorAtPublic();
54
55
        //Create symlink for uploads path
56
        $this->symlinkForUpload();
57
58
        //Crate symlink for assets
59
        $this->symlinkForAsset();
60
      
61
62
		if($this->confirm('Do you have setting the database configuration at .env ?')) {
63
            $this->installCrudbooster();
64
		}else{
65
			$this->info('Setup Aborted !');
66
			$this->info('Please setting the database configuration for first !');
67
		}
68
69
		$this->printFooter();
70
        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...
71
	}
72
73
	private function printHeader() {
74
		$this->info("
75
76
#     __________  __  ______  ____                   __           
77
#    / ____/ __ \/ / / / __ \/ __ )____  ____  _____/ /____  _____
78
#   / /   / /_/ / / / / / / / __  / __ \/ __ \/ ___/ __/ _ \/ ___/
79
#  / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__  ) /_/  __/ /    
80
#  \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/     
81
#                                                                                                                       
82
			");
83
        $this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------');
84
        $this->info('====================================================================');
85
    }
86
87
    private function printFooter($success = true)
88
    {
89
        $this->info('--');
90
        $this->info('Homepage : http://www.crudbooster.com');
91
        $this->info('Github : https://github.com/crocodic-studio/crudbooster');
92
        $this->info('Documentation : https://github.com/crocodic-studio/crudbooster/blob/master/docs/en/index.md');
93
        $this->info('====================================================================');
94
        if ($success == true) {
95
            $this->info('------------------- :===: Completed !! :===: ------------------------');
96
        } else {
97
            $this->info('------------------- :===:  Failed !!  :===: ------------------------');
98
        }
99
    }
100
101
    /**
102
     * Get the composer command for the environment.
103
     *
104
     * @return string
105
     */
106
    protected function findComposer()
107
    {
108
        if (file_exists(getcwd().'/composer.phar')) {
109
            return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
110
        }
111
112
        return 'composer';
113
    }
114
115
    private function symlinkForUpload()
116
    {
117
        $this->info('Checking public/uploads symlink...');
118
        if (!file_exists(public_path('uploads'))) {
0 ignored issues
show
Bug introduced by
The function public_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

118
        if (!file_exists(/** @scrutinizer ignore-call */ public_path('uploads'))) {
Loading history...
119
            $this->info('Creating public/uploads symlink...');
120
            app('files')->link(storage_path('app'), public_path('uploads'));
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

120
            /** @scrutinizer ignore-call */ 
121
            app('files')->link(storage_path('app'), public_path('uploads'));
Loading history...
Bug introduced by
The function storage_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

120
            app('files')->link(/** @scrutinizer ignore-call */ storage_path('app'), public_path('uploads'));
Loading history...
121
            return;
122
        }
123
        $uploadPath = public_path('uploads');
124
        $this->info('Upload Path: '.$uploadPath);
125
        if (realpath($uploadPath) == $uploadPath) {
126
            $this->info('Remove the existing uploads dir, and create a symlink for it...');
127
            rrmdir(public_path('uploads'));
128
            app('files')->link(storage_path('app'), public_path('uploads'));
129
        }
130
    }
131
132
    private function symlinkForAsset()
133
    {
134
        $this->info('Checking public/vendor/crudbooster symlink...');
135
136
137
        $vendorPath = public_path('vendor'.DIRECTORY_SEPARATOR.'crudbooster');
0 ignored issues
show
Bug introduced by
The function public_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

137
        $vendorPath = /** @scrutinizer ignore-call */ public_path('vendor'.DIRECTORY_SEPARATOR.'crudbooster');
Loading history...
138
139
        if (!file_exists($vendorPath)) {
140
            $this->info('Creating public/vendor/crudbooster symlink...');
141
            app('files')->link(__DIR__.'/../assets', public_path('vendor/crudbooster'));
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

141
            /** @scrutinizer ignore-call */ 
142
            app('files')->link(__DIR__.'/../assets', public_path('vendor/crudbooster'));
Loading history...
142
            return ;
143
        }
144
145
        $this->info('Vendor Path: '.$vendorPath);
146
147
        if (realpath($vendorPath) == $vendorPath) {
148
            $this->info('Removing public/vendor/crudbooster dir, instead of creating a symlink...');
149
            rrmdir($vendorPath);
150
            app('files')->link(__DIR__.'/../assets', $vendorPath);
151
        }
152
    }
153
154
    private function removeDefaultMigrations()
155
    {
156
        $this->info('I remove some default migration files from laravel...');
157
        @unlink(base_path('database/migrations/2014_10_12_000000_create_users_table.php'));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

157
        /** @scrutinizer ignore-unhandled */ @unlink(base_path('database/migrations/2014_10_12_000000_create_users_table.php'));

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

157
        @unlink(/** @scrutinizer ignore-call */ base_path('database/migrations/2014_10_12_000000_create_users_table.php'));
Loading history...
158
        @unlink(base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php'));
159
160
    }
161
162
    private function installCrudbooster()
163
    {
164
        $this->info('Publishing CRUDBooster needs file...');
165
        $this->callSilent('vendor:publish', ['--provider' => 'crocodicstudio\\crudbooster\\CRUDBoosterServiceProvider', '--force' => true]);
166
        $this->callSilent('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]);
167
        $this->callSilent('vendor:publish', ['--tag' => 'cb_lfm', '--force' => true]);
168
        $this->callSilent('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]);
169
170
        $this->info('Dumping the autoloaded files and reloading all new files...');
171
        $composer = $this->findComposer();
172
        $process = new Process($composer.' dumpautoload');
173
        $process->setWorkingDirectory(base_path())->run();
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

173
        $process->setWorkingDirectory(/** @scrutinizer ignore-call */ base_path())->run();
Loading history...
174
175
        $this->info('Migrating database...');
176
        $this->call('migrate', ['--path'=> '\database\migrations\crudbooster']);
177
178
        if (! class_exists('CBSeeder')) {
179
            require_once __DIR__.'/../database/seeds/CBSeeder.php';
180
        }
181
        $this->callSilent('db:seed', ['--class' => 'CBSeeder']);
182
        $this->call('config:clear');
183
        $this->call('optimize');
184
185
        $this->info('Installing CRUDBooster Is Completed ! Thank You :)');
186
    }
187
188
    private function createVendorAtPublic()
189
    {
190
        $this->info('Checking public/vendor directory...');
191
        if (! file_exists(public_path('vendor'))) {
0 ignored issues
show
Bug introduced by
The function public_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

191
        if (! file_exists(/** @scrutinizer ignore-call */ public_path('vendor'))) {
Loading history...
192
            mkdir(public_path('vendor'), 0777);
193
        }
194
195
        if (! is_writable(public_path('vendor'))) {
196
            $this->info('Setup aborted !');
197
            $this->info('Please set public/vendor directory to writable 0777');
198
            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...
199
        }
200
    }
201
}
202