Conditions | 7 |
Paths | 40 |
Total Lines | 141 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function handle() |
||
42 | { |
||
43 | // Progress count |
||
44 | $progressCount = 0; |
||
45 | |||
46 | // Questions |
||
47 | if ($this->confirm('Would you like to install auth scaffolding?')) { |
||
48 | $authScaffold = true; |
||
49 | $progressCount++; |
||
50 | |||
51 | // Admin User |
||
52 | $name = $this->ask('Enter a name for the admin user.'); |
||
53 | $email = $this->ask('Enter the admin user\'s email address'); |
||
54 | $password = $this->secret('Enter the admin user\'s password'); |
||
55 | } else { |
||
56 | $authScaffold = false; |
||
57 | } |
||
58 | |||
59 | // Setup the output |
||
60 | $output = new ConsoleOutput(); |
||
61 | $output->setFormatter(new OutputFormatter(true)); |
||
62 | |||
63 | // create a new progress bar (4 units + $progressCount) |
||
64 | $progress = new ProgressBar($output, 4 + $progressCount); |
||
65 | $progress->setFormat('Progress: [%bar%] %message%'); |
||
66 | $progress->setOverwrite(false); |
||
67 | |||
68 | // Install Node modules |
||
69 | $progress->setMessage('Installing Node modules'); |
||
70 | $progress->advance(); |
||
71 | $this->runProcess('npm install', 300); |
||
72 | |||
73 | // Check dependencies (Bulma) |
||
74 | $progress->setMessage('Installing dependencies'); |
||
75 | $progress->start(); |
||
76 | |||
77 | if ($this->checkPathExists('node_modules/bulma/') === false) { |
||
78 | $this->runProcess('npm install bulma --save-dev'); |
||
79 | } |
||
80 | |||
81 | if ($this->checkPathExists('node_modules/font-awesome/') === false) { |
||
82 | $this->runProcess('npm install font-awesome --save-dev'); |
||
83 | } |
||
84 | |||
85 | // Auth Scaffolding |
||
86 | if ($authScaffold === true) { |
||
87 | |||
88 | // Generate auth scaffolding |
||
89 | $progress->setMessage('Generating auth scaffolding'); |
||
90 | $progress->advance(); |
||
91 | $this->callSilent('make:auth'); |
||
92 | |||
93 | if ($this->filesystem->exists('vendor/laravel/passport') === false) { |
||
94 | |||
95 | // Install Passport |
||
96 | $this->runProcess('composer require laravel/passport', 300); |
||
97 | |||
98 | // Add the service provider for passport |
||
99 | $file = config_path().'/app.php'; |
||
100 | $search = 'Laravel\Tinker\TinkerServiceProvider::class,'; |
||
101 | $insert = 'Laravel\Passport\PassportServiceProvider::class,'; |
||
102 | $replace = $search."\n \t \t".$insert; |
||
103 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
104 | |||
105 | // Add HasApiTokens to the user model |
||
106 | $file = app_path().'/User.php'; |
||
107 | $search = 'use Illuminate\Notifications\Notifiable;'; |
||
108 | $insert = 'use Laravel\Passport\HasApiTokens;'; |
||
109 | $replace = $insert."\n".$search; |
||
110 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
111 | |||
112 | $search = 'use Notifiable;'; |
||
113 | $replace = 'use HasApiTokens, Notifiable;'; |
||
114 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
115 | |||
116 | // Add Passport to AuthServiceProvider |
||
117 | $file = app_path().'/Providers/AuthServiceProvider.php'; |
||
118 | $search = '$this->registerPolicies();'; |
||
119 | $insert = 'Passport::routes();'; |
||
120 | $replace = $search."\n \t \t".$insert; |
||
121 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
122 | |||
123 | $file = app_path().'/Providers/AuthServiceProvider.php'; |
||
124 | $search = 'use Illuminate\Support\Facades\Gate;'; |
||
125 | $insert = 'use Laravel\Passport\Passport;'; |
||
126 | $replace = $search."\n".$insert; |
||
127 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
128 | |||
129 | // Change api provider to passport in auth config file |
||
130 | $file = config_path().'/auth.php'; |
||
131 | $search = '\'driver\' => \'token\','; |
||
132 | $insert = '\'driver\' => \'passport\','; |
||
133 | file_put_contents($file, str_replace($search, $insert, file_get_contents($file))); |
||
134 | |||
135 | // Add CreateFreshApiToken to HTTP Kernel |
||
136 | $file = app_path().'/Http/Kernel.php'; |
||
137 | $search = '\App\Http\Middleware\VerifyCsrfToken::class,'; |
||
138 | $insert = '\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,'; |
||
139 | $replace = $search."\n \t \t \t".$insert; |
||
140 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
141 | |||
142 | // Run the passport migrations and install passport |
||
143 | $this->runProcess('php artisan migrate'); |
||
144 | $this->runProcess('php artisan passport:install'); |
||
145 | } |
||
146 | |||
147 | // Create admin user |
||
148 | if (isset($name, $email, $password)) { |
||
149 | $user = new User(); |
||
150 | $user->name = $name; |
||
151 | $user->email = $email; |
||
152 | $user->password = bcrypt($password); |
||
153 | $user->save(); |
||
154 | } |
||
155 | } |
||
156 | |||
157 | // Publish assets |
||
158 | $progress->setMessage('Publishing the Bulma assets and config files'); |
||
159 | $progress->advance(); |
||
160 | $this->callSilent('vendor:publish', [ |
||
161 | '--provider' => 'rustymulvaney\bulma\BulmaServiceProvider', |
||
162 | '--tag' => 'install', |
||
163 | '--force' => true, |
||
164 | ]); |
||
165 | |||
166 | // Fix package.json reference to cross-env |
||
167 | $progress->setMessage('Fix package.json reference to cross-env'); |
||
168 | $progress->advance(); |
||
169 | $file = base_path().'/package.json'; |
||
170 | $search = 'cross-env/bin'; |
||
171 | $replace = 'cross-env/dist/bin'; |
||
172 | file_put_contents($file, str_replace($search, $replace, file_get_contents($file))); |
||
173 | |||
174 | // Run Laravel Mix |
||
175 | $progress->setMessage('Running Laravel Mix'); |
||
176 | $progress->advance(); |
||
177 | $this->runProcess('npm run dev'); |
||
178 | |||
179 | // End the progress bar |
||
180 | $progress->finish(); |
||
181 | } |
||
182 | |||
200 |