Completed
Push — master ( 3ac274...255bc6 )
by Mokhlas
01:24
created

MultiAuthPrepare::handle()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 83
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 83
rs 8.4888
c 0
b 0
f 0
cc 4
eloc 57
nc 6
nop 0

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
2
3
namespace iMokhles\MultiAuthCommand\Command;
4
5
6
use Illuminate\Database\Console\Migrations\BaseCommand;
7
use Illuminate\Database\Migrations\MigrationCreator;
8
use Illuminate\Support\Composer;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Process\Exception\ProcessFailedException;
12
use Symfony\Component\Process\Process;
13
14
class MultiAuthPrepare extends BaseCommand
15
{
16
    /**
17
     * @var
18
     */
19
    protected $progressBar;
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'make:multi-auth {name} {--is_backpack= : Check if backpack or not to publish correct views}';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Create MultiAuth for your project';
33
34
    /**
35
     * The migration creator instance.
36
     *
37
     * @var \Illuminate\Database\Migrations\MigrationCreator
38
     */
39
    protected $creator;
40
41
    /**
42
     * The Composer instance.
43
     *
44
     * @var \Illuminate\Support\Composer
45
     */
46
    protected $composer;
47
48
    /**
49
     * Create a new migration install command instance.
50
     *
51
     * @param  \Illuminate\Database\Migrations\MigrationCreator  $creator
52
     * @param  \Illuminate\Support\Composer  $composer
53
     */
54
    public function __construct(MigrationCreator $creator, Composer $composer)
55
    {
56
        parent::__construct();
57
        $this->creator = $creator;
58
        $this->composer = $composer;
59
    }
60
61
    /**
62
     * Execute the console command.
63
     *
64
     * @return boolean
65
     */
66
    public function handle()
67
    {
68
69
        $this->progressBar = $this->output->createProgressBar(14);
70
        $this->progressBar->start();
71
72
        $this->info("Preparing For MultiAuth. Please wait...");
73
        $this->progressBar->advance();
74
75
        $is_backpack = $this->option('is_backpack');
76
77
        $is_backpack_enabled = false;
78
        if ($is_backpack == 1) {
79
            $is_backpack_enabled = true;
80
        }
81
82
        if ($this->isAlreadySetup($is_backpack_enabled)) {
83
            $this->info("installing migrations...");
84
            $this->installMigration($is_backpack_enabled);
85
            $this->progressBar->advance();
86
87
            $this->info("installing models...");
88
            $this->installModel($is_backpack_enabled);
89
            $this->progressBar->advance();
90
91
            $this->info("installing route maps...");
92
            $this->installRouteMaps($is_backpack_enabled);
93
            $this->progressBar->advance();
94
95
            $this->info("installing route files...");
96
            $this->installRouteFiles($is_backpack_enabled);
97
            $this->progressBar->advance();
98
99
            $this->info("installing controllers...");
100
            $this->installControllers($is_backpack_enabled);
101
            $this->progressBar->advance();
102
103
            $this->info("installing requests...");
104
            $this->installRequests($is_backpack_enabled);
105
            $this->progressBar->advance();
106
107
            $this->info("installing configs...");
108
            $this->installConfigs($is_backpack_enabled);
109
            $this->progressBar->advance();
110
111
            $this->info("installing middleware...");
112
            $this->installMiddleware($is_backpack_enabled);
113
            $this->progressBar->advance();
114
115
            $this->info("installing unauthenticated function...");
116
            $this->installUnauthenticated($is_backpack_enabled);
117
            $this->progressBar->advance();
118
119
            $this->info("installing views...");
120
            $this->installView($is_backpack_enabled);
121
            $this->progressBar->advance();
122
123
            $this->info("installing prologue alert...");
124
            $this->installPrologueAlert($is_backpack_enabled);
125
            $this->progressBar->advance();
126
127
            $this->info("dump autoload...");
128
            $this->composer->dumpAutoloads();
129
            $this->progressBar->advance();
130
131
            if ($is_backpack_enabled == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
132
                $this->info("finished MultiAuth.");
133
                $this->progressBar->advance();
134
            } else {
135
                $this->info("finished MultiAuth for Backpack.");
136
                $this->progressBar->advance();
137
            }
138
        } else {
139
            $this->info("failed. already setup");
140
            $this->progressBar->advance();
141
            $this->progressBar->finish();
142
        }
143
144
145
146
147
        return true;
148
    }
149
150
    /**
151
     * Publish Prologue Alert
152
     *
153
     * @return boolean
154
     */
155
    public function installPrologueAlert($is_backpack_enabled) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
156
        $alertsConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."prologue/alerts.php";
157
        if (!file_exists($alertsConfigFile)) {
158
            $this->executeProcess('php artisan vendor:publish --provider="Prologue\Alerts\AlertsServiceProvider"',
159
                'publishing config for notifications - prologue/alerts');
160
        }
161
162
        return true;
163
    }
164
165
    /**
166
     * Install Migration.
167
     *
168
     * @return boolean
169
     */
170
    public function installMigration($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
171
    {
172
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
173
        $name = ucfirst($this->getParsedNameInput());
174
        $namePlural = str_plural($name);
175
176
177
178
        $modelTableContent = file_get_contents(__DIR__ . '/../Migration/modelTable.stub');
179
        $modelTableContentNew = str_replace([
180
            '{{$namePlural}}',
181
            '{{$nameSmallPlural}}',
182
        ], [
183
            $namePlural,
184
            $nameSmallPlural
185
        ], $modelTableContent);
186
187
188
        $modelResetPasswordTableContent = file_get_contents(__DIR__ . '/../Migration/passwordResetsTable.stub');
189
        $modelResetPasswordTableContentNew = str_replace([
190
            '{{$namePlural}}',
191
            '{{$nameSmallPlural}}',
192
        ], [
193
            $namePlural,
194
            $nameSmallPlural
195
        ], $modelResetPasswordTableContent);
196
197
198
        $migrationName = date('Y_m_d_His') . '_'.'create_' . str_plural(snake_case($name)) .'_table.php';
199
        $migrationModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationName;
200
        file_put_contents($migrationModelPath, $modelTableContentNew);
201
202
        $migrationResetName = date('Y_m_d_His') . '_'
203
            .'create_' . str_plural(snake_case($name))
204
            .'_password_resets_table.php';
205
        $migrationResetModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationResetName;
206
        file_put_contents($migrationResetModelPath, $modelResetPasswordTableContentNew);
207
208
        return true;
209
210
    }
211
212
213
    /**
214
     * Install Model.
215
     *
216
     * @return boolean
217
     */
218
    public function installModel($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
219
    {
220
        $nameSmall = snake_case($this->getParsedNameInput());
221
        $name = ucfirst($this->getParsedNameInput());
222
223
224
        $arrayToChange = [
225
            '{{$name}}',
226
        ];
227
228
        $newChanges = [
229
            $name,
230
        ];
231
        if ($is_backpack_enabled == true) {
232
            $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
233
            array_push($arrayToChange, '{{$nameSmallPlural}}');
234
            array_push($newChanges, $nameSmallPlural);
235
236
            $modelContent = file_get_contents(__DIR__ . '/../Backpack/Model/model.stub');
237
            $modelContentNew = str_replace($arrayToChange, $newChanges, $modelContent);
238
        } else {
239
            $modelContent = file_get_contents(__DIR__ . '/../Model/model.stub');
240
            $modelContentNew = str_replace($arrayToChange, $newChanges, $modelContent);
241
        }
242
243
        $createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Models";
244
        if (!file_exists($createFolder)) {
245
            mkdir($createFolder);
246
        }
247
248
        $modelPath = $createFolder.DIRECTORY_SEPARATOR.$name.".php";
249
        file_put_contents($modelPath, $modelContentNew);
250
251
252
253
        $resetNotificationContent = file_get_contents(__DIR__ . '/../Notification/resetPasswordNotification.stub');
254
        $resetNotificationContentNew = str_replace([
255
            '{{$name}}',
256
            '{{$nameSmall}}',
257
        ], [
258
            $name,
259
            $nameSmall
260
        ], $resetNotificationContent);
261
262
        $createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Notifications";
263
        if (!file_exists($createFolder)) {
264
            mkdir($createFolder);
265
        }
266
267
        $resetNotificationPath = $createFolder.DIRECTORY_SEPARATOR.$name."ResetPasswordNotification.php";
268
        file_put_contents($resetNotificationPath, $resetNotificationContentNew);
269
270
        return true;
271
272
    }
273
274
    /**
275
     * Install View.
276
     *
277
     * @return boolean
278
     */
279
    public function installView($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
280
    {
281
        $nameSmall = snake_case($this->getParsedNameInput());
282
        $name = ucfirst($this->getParsedNameInput());
283
284
        if ($is_backpack_enabled == true) {
285
            $appBlade = file_get_contents(__DIR__ . '/../Backpack/Views/layouts/layout.blade.stub');
0 ignored issues
show
Unused Code introduced by
$appBlade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
286
        } else {
287
            $appBlade = file_get_contents(__DIR__ . '/../Views/layouts/app.blade.stub');
0 ignored issues
show
Unused Code introduced by
$appBlade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
288
        }
289
290
291
292
293
294
        if ($is_backpack_enabled == true) {
295
            $appBlade = file_get_contents(__DIR__ . '/../Backpack/Views/layouts/layout.blade.stub');
296
            $homeBlade = file_get_contents(__DIR__ . '/../Backpack/Views/home.blade.stub');
297
            $loginBlade = file_get_contents(__DIR__ . '/../Backpack/Views/auth/login.blade.stub');
298
            $registerBlade = file_get_contents(__DIR__ . '/../Backpack/Views/auth/register.blade.stub');
299
            $resetBlade = file_get_contents(__DIR__ . '/../Backpack/Views/auth/passwords/reset.blade.stub');
300
            $emailBlade = file_get_contents(__DIR__ . '/../Backpack/Views/auth/passwords/email.blade.stub');
301
302
            $update_infoBlade = file_get_contents(__DIR__
303
                . '/../Backpack/Views/auth/account/update_info.blade.stub');
304
            $change_passwordBlade = file_get_contents(__DIR__
305
                . '/../Backpack/Views/auth/account/change_password.blade.stub');
306
307
            $sidemenuBlade = file_get_contents(__DIR__
308
                . '/../Backpack/Views/auth/account/sidemenu.blade.stub');
309
            $main_headerBlade = file_get_contents(__DIR__
310
                . '/../Backpack/Views/inc/main_header.blade.stub');
311
            $menuBlade = file_get_contents(__DIR__
312
                . '/../Backpack/Views/inc/menu.blade.stub');
313
            $sidebarBlade = file_get_contents(__DIR__
314
                . '/../Backpack/Views/inc/sidebar.blade.stub');
315
            $sidebar_user_panelBlade = file_get_contents(__DIR__
316
                . '/../Backpack/Views/inc/sidebar_user_panel.blade.stub');
317
318
319
        } else {
320
            $welcomeBlade = file_get_contents(__DIR__ . '/../Views/welcome.blade.stub');
321
            $appBlade = file_get_contents(__DIR__ . '/../Views/layouts/app.blade.stub');
322
            $homeBlade = file_get_contents(__DIR__ . '/../Views/home.blade.stub');
323
            $loginBlade = file_get_contents(__DIR__ . '/../Views/auth/login.blade.stub');
324
            $registerBlade = file_get_contents(__DIR__ . '/../Views/auth/register.blade.stub');
325
            $resetBlade = file_get_contents(__DIR__ . '/../Views/auth/passwords/reset.blade.stub');
326
            $emailBlade = file_get_contents(__DIR__ . '/../Views/auth/passwords/email.blade.stub');
327
            $update_infoBlade = file_get_contents(__DIR__
328
                . '/../Views/auth/account/update_info.blade.stub');
329
            $change_passwordBlade = file_get_contents(__DIR__
330
                . '/../Views/auth/account/change_password.blade.stub');
331
332
        }
333
334
335
        $createFolder = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall";
336
        if (!file_exists($createFolder)) {
337
            mkdir($createFolder);
338
        }
339
340
        $createFolderLayouts = $this->getViewsFolderPath().DIRECTORY_SEPARATOR
341
            ."$nameSmall"
342
            .DIRECTORY_SEPARATOR."layouts";
343
        if (!file_exists($createFolderLayouts)) {
344
            mkdir($createFolderLayouts);
345
        }
346
347
        $createFolderInc = $this->getViewsFolderPath().DIRECTORY_SEPARATOR
348
            ."$nameSmall"
349
            .DIRECTORY_SEPARATOR."inc";
350
        if (!file_exists($createFolderInc)) {
351
            mkdir($createFolderInc);
352
        }
353
354
        $createFolderAuth = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall"
355
            .DIRECTORY_SEPARATOR."auth";
356
        if (!file_exists($createFolderAuth)) {
357
            mkdir($createFolderAuth);
358
        }
359
360
        $createFolderAuthPasswords = $this->getViewsFolderPath().DIRECTORY_SEPARATOR.
361
            "$nameSmall".DIRECTORY_SEPARATOR
362
            ."auth".DIRECTORY_SEPARATOR."passwords";
363
        if (!file_exists($createFolderAuthPasswords)) {
364
            mkdir($createFolderAuthPasswords);
365
        }
366
367
        $createFolderAuthAccount = $this->getViewsFolderPath().DIRECTORY_SEPARATOR.
368
            "$nameSmall".DIRECTORY_SEPARATOR
369
            ."auth".DIRECTORY_SEPARATOR."account";
370
        if (!file_exists($createFolderAuthAccount)) {
371
            mkdir($createFolderAuthAccount);
372
        }
373
374
        $appBladeNew = str_replace([
375
            '{{$nameSmall}}',
376
        ], [
377
            $nameSmall
378
        ], $appBlade);
379
380
        $homeBladeNew = str_replace([
381
            '{{$nameSmall}}',
382
            '{{$name}}',
383
384
        ], [
385
            $nameSmall
386
        ], $homeBlade);
387
388
        $loginBladeNew = str_replace([
389
            '{{$nameSmall}}',
390
        ], [
391
            $nameSmall
392
        ], $loginBlade);
393
394
        $registerBladeNew = str_replace([
395
            '{{$nameSmall}}',
396
        ], [
397
            $nameSmall
398
        ], $registerBlade);
399
400
        $emailBladeNew = str_replace([
401
            '{{$nameSmall}}',
402
        ], [
403
            $nameSmall
404
        ], $emailBlade);
405
406
        $resetBladeNew = str_replace([
407
            '{{$nameSmall}}',
408
        ], [
409
            $nameSmall
410
        ], $resetBlade);
411
412
        $update_infoBladeNew = str_replace([
413
            '{{$nameSmall}}',
414
            '{{$name}}',
415
        ], [
416
            $nameSmall,
417
            $name
418
        ], $update_infoBlade);
419
420
        $change_passwordBladeNew = str_replace([
421
            '{{$nameSmall}}',
422
        ], [
423
            $nameSmall,
424
            $name
425
        ], $change_passwordBlade);
426
427
428
        if ($is_backpack_enabled == true) {
429
            $sidemenuBladeNew = str_replace([
0 ignored issues
show
Unused Code introduced by
$sidemenuBladeNew is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
430
                '{{$nameSmall}}',
431
            ], [
432
                $nameSmall
433
            ], $sidemenuBlade);
0 ignored issues
show
Bug introduced by
The variable $sidemenuBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
434
435
            $main_headerBladeNew = str_replace([
436
                '{{$nameSmall}}',
437
            ], [
438
                $nameSmall
439
            ], $main_headerBlade);
0 ignored issues
show
Bug introduced by
The variable $main_headerBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
440
441
            $menuBladeNew = str_replace([
442
                '{{$nameSmall}}',
443
            ], [
444
                $nameSmall
445
            ], $menuBlade);
0 ignored issues
show
Bug introduced by
The variable $menuBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
446
447
            $sidebarBladeNew = str_replace([
448
                '{{$nameSmall}}',
449
            ], [
450
                $nameSmall
451
            ], $sidebarBlade);
0 ignored issues
show
Bug introduced by
The variable $sidebarBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
452
453
            $sidebar_user_panelBladeNew = str_replace([
454
                '{{$nameSmall}}',
455
            ], [
456
                $nameSmall
457
            ], $sidebar_user_panelBlade);
0 ignored issues
show
Bug introduced by
The variable $sidebar_user_panelBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
458
459
460
            file_put_contents($createFolderLayouts.'/layout.blade.php', $appBladeNew);
461
462
            file_put_contents($createFolderAuthAccount.'/sidemenu.blade.php', $main_headerBladeNew);
463
            file_put_contents($createFolderInc.'/main_header.blade.php', $main_headerBladeNew);
464
            file_put_contents($createFolderInc.'/menu.blade.php', $menuBladeNew);
465
            file_put_contents($createFolderInc.'/sidebar.blade.php', $sidebarBladeNew);
466
            file_put_contents($createFolderInc.'/sidebar_user_panel.blade.php', $sidebar_user_panelBladeNew);
467
468
        } else {
469
            $welcomeBladeNew = str_replace([
470
                '{{$nameSmall}}',
471
            ], [
472
                $nameSmall
473
            ], $welcomeBlade);
0 ignored issues
show
Bug introduced by
The variable $welcomeBlade does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
474
            file_put_contents($createFolderLayouts.'/app.blade.php', $appBladeNew);
475
            file_put_contents($createFolder.'/welcome.blade.php', $welcomeBladeNew);
476
        }
477
        file_put_contents($createFolder.'/home.blade.php', $homeBladeNew);
478
        file_put_contents($createFolderAuth.'/login.blade.php', $loginBladeNew);
479
        file_put_contents($createFolderAuth.'/register.blade.php', $registerBladeNew);
480
        file_put_contents($createFolderAuthPasswords.'/email.blade.php', $emailBladeNew);
481
        file_put_contents($createFolderAuthPasswords.'/reset.blade.php', $resetBladeNew);
482
483
        file_put_contents($createFolderAuthAccount.'/update_info.blade.php', $update_infoBladeNew);
484
        file_put_contents($createFolderAuthAccount.'/change_password.blade.php', $change_passwordBladeNew);
485
486
        return true;
487
488
    }
489
490
    /**
491
     * Install RouteMaps.
492
     *
493
     * @return boolean
494
     */
495
496
    public function installRouteMaps($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
497
    {
498
        $nameSmall = snake_case($this->getParsedNameInput());
499
        $name = ucfirst($this->getParsedNameInput());
500
        $mapCallFunction = file_get_contents(__DIR__ . '/../Route/mapRoute.stub');
501
        $mapCallFunctionNew = str_replace('{{$name}}', "$name", $mapCallFunction);
502
        $this->insert($this->getRouteServicesPath(), '$this->mapWebRoutes();', $mapCallFunctionNew, true);
503
        $mapFunction = file_get_contents(__DIR__ . '/../Route/mapRouteFunction.stub');
504
        $mapFunctionNew = str_replace([
505
            '{{$name}}',
506
            '{{$nameSmall}}'
507
        ], [
508
            "$name",
509
            "$nameSmall"
510
        ], $mapFunction);
511
        $this->insert($this->getRouteServicesPath(), '        //
512
    }', $mapFunctionNew, true);
513
        return true;
514
    }
515
516
    public function isAlreadySetup($is_backpack_enabled) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
517
        $name = ucfirst($this->getParsedNameInput());
518
519
        $routeServicesContent = file_get_contents($this->getRouteServicesPath());
520
521
        if (str_contains($routeServicesContent,'$this->map'.$name.'Routes();')) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return str_contains($rou.... $name . 'Routes();');.
Loading history...
522
            return true;
523
        }
524
        return false;
525
    }
526
527
    /**
528
     * Install RouteFile.
529
     *
530
     * @return boolean
531
     */
532
533
    public function installRouteFiles($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
534
    {
535
        $nameSmall = snake_case($this->getParsedNameInput());
536
        $name = ucfirst($this->getParsedNameInput());
537
        $createFolder = $this->getRoutesFolderPath().DIRECTORY_SEPARATOR.$nameSmall;
538
        if (!file_exists($createFolder)) {
539
            mkdir($createFolder);
540
        }
541
        $routeFileContent = file_get_contents(__DIR__ . '/../Route/routeFile.stub');
542
        $routeFileContentNew = str_replace([
543
            '{{$name}}',
544
            '{{$nameSmall}}'
545
        ], [
546
            "$name",
547
            "$nameSmall"
548
        ], $routeFileContent);
549
        $routeFile = $createFolder.DIRECTORY_SEPARATOR.$nameSmall.".php";
550
        file_put_contents($routeFile, $routeFileContentNew);
551
        return true;
552
    }
553
554
    /**
555
     * Install Requests.
556
     *
557
     * @return boolean
558
     */
559
560
    public function installRequests($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
561
    {
562
        $nameSmall = snake_case($this->getParsedNameInput());
563
        $name = ucfirst($this->getParsedNameInput());
564
565
        $nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name;
566
        if (!file_exists($nameFolder)) {
567
            mkdir($nameFolder);
568
        }
569
570
        $requestsFolder = $nameFolder.DIRECTORY_SEPARATOR."Requests";
571
        if (!file_exists($requestsFolder)) {
572
            mkdir($requestsFolder);
573
        }
574
        $accountInfoContent = file_get_contents(__DIR__ . '/../Request/AccountInfoRequest.stub');
575
        $changePasswordContent = file_get_contents(__DIR__ . '/../Request/ChangePasswordRequest.stub');
576
577
        $accountInfoContentNew = str_replace([
578
            '{{$name}}',
579
            '{{$nameSmall}}'
580
        ], [
581
            "$name",
582
            "$nameSmall"
583
        ], $accountInfoContent);
584
585
        $changePasswordContentNew = str_replace([
586
            '{{$name}}',
587
            '{{$nameSmall}}'
588
        ], [
589
            "$name",
590
            "$nameSmall"
591
        ], $changePasswordContent);
592
593
        $accountInfoFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}AccountInfoRequest.php";
594
        $changePasswordFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}ChangePasswordRequest.php";
595
596
        file_put_contents($accountInfoFile, $accountInfoContentNew);
597
        file_put_contents($changePasswordFile, $changePasswordContentNew);
598
599
        return true;
600
601
    }
602
    /**
603
     * Install Controller.
604
     *
605
     * @return boolean
606
     */
607
608
    public function installControllers($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
609
    {
610
        $nameSmall = snake_case($this->getParsedNameInput());
611
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
612
        $name = ucfirst($this->getParsedNameInput());
613
614
        $nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name;
615
        if (!file_exists($nameFolder)) {
616
            mkdir($nameFolder);
617
        }
618
619
        $authFolder = $nameFolder.DIRECTORY_SEPARATOR."Auth";
620
        if (!file_exists($authFolder)) {
621
            mkdir($authFolder);
622
        }
623
624
        $controllerContent = file_get_contents(__DIR__ . '/../Controllers/Controller.stub');
625
        $homeControllerContent = file_get_contents(__DIR__ . '/../Controllers/HomeController.stub');
626
        $loginControllerContent = file_get_contents(__DIR__ . '/../Controllers/Auth/LoginController.stub');
627
        $forgotControllerContent = file_get_contents(__DIR__ . '/../Controllers/Auth/ForgotPasswordController.stub');
628
        $registerControllerContent = file_get_contents(__DIR__ . '/../Controllers/Auth/RegisterController.stub');
629
        $resetControllerContent = file_get_contents(__DIR__ . '/../Controllers/Auth/ResetPasswordController.stub');
630
        $myAccountControllerContent = file_get_contents(__DIR__ . '/../Controllers/Auth/MyAccountController.stub');
631
632
        $controllerFileContentNew = str_replace('{{$name}}', "$name", $controllerContent);
633
634
        $homeFileContentNew = str_replace([
635
            '{{$name}}',
636
            '{{$nameSmall}}'
637
        ], [
638
            "$name",
639
            "$nameSmall"
640
        ], $homeControllerContent);
641
642
        $loginFileContentNew = str_replace([
643
            '{{$name}}',
644
            '{{$nameSmall}}'
645
        ], [
646
            "$name",
647
            "$nameSmall"
648
        ], $loginControllerContent);
649
650
        $forgotFileContentNew = str_replace([
651
            '{{$name}}',
652
            '{{$nameSmall}}',
653
            '{{$nameSmallPlural}}'
654
        ], [
655
            "$name",
656
            "$nameSmall",
657
            "$nameSmallPlural"
658
        ], $forgotControllerContent);
659
660
        $registerFileContentNew = str_replace([
661
            '{{$name}}',
662
            '{{$nameSmall}}',
663
            '{{$nameSmallPlural}}'
664
        ], [
665
            "$name",
666
            "$nameSmall",
667
            "$nameSmallPlural"
668
        ], $registerControllerContent);
669
670
        $resetFileContentNew = str_replace([
671
            '{{$name}}',
672
            '{{$nameSmall}}',
673
            '{{$nameSmallPlural}}'
674
        ], [
675
            "$name",
676
            "$nameSmall",
677
            "$nameSmallPlural"
678
        ], $resetControllerContent);
679
680
        $myAccountFileContentNew = str_replace([
681
            '{{$name}}',
682
            '{{$nameSmall}}'
683
        ], [
684
            "$name",
685
            "$nameSmall"
686
        ], $myAccountControllerContent);
687
688
        $controllerFile = $nameFolder.DIRECTORY_SEPARATOR."Controller.php";
689
        $homeFile = $nameFolder.DIRECTORY_SEPARATOR."HomeController.php";
690
        $loginFile = $authFolder.DIRECTORY_SEPARATOR."LoginController.php";
691
        $forgotFile = $authFolder.DIRECTORY_SEPARATOR."ForgotPasswordController.php";
692
        $registerFile = $authFolder.DIRECTORY_SEPARATOR."RegisterController.php";
693
        $resetFile = $authFolder.DIRECTORY_SEPARATOR."ResetPasswordController.php";
694
695
        $myAccountFile = $authFolder.DIRECTORY_SEPARATOR."{$name}AccountController.php";
696
697
698
        file_put_contents($controllerFile, $controllerFileContentNew);
699
        file_put_contents($homeFile, $homeFileContentNew);
700
        file_put_contents($loginFile, $loginFileContentNew);
701
        file_put_contents($forgotFile, $forgotFileContentNew);
702
        file_put_contents($registerFile, $registerFileContentNew);
703
        file_put_contents($resetFile, $resetFileContentNew);
704
        file_put_contents($myAccountFile, $myAccountFileContentNew);
705
706
        return true;
707
708
    }
709
710
    /**
711
     * Install Configs.
712
     *
713
     * @return boolean
714
     */
715
716
    public function installConfigs($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
717
    {
718
        $nameSmall = snake_case($this->getParsedNameInput());
719
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
720
        $name = ucfirst($this->getParsedNameInput());
721
722
        $authConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."auth.php";
723
724
        $guardContent = file_get_contents(__DIR__ . '/../Config/guard.stub');
725
        $passwordContent = file_get_contents(__DIR__ . '/../Config/password.stub');
726
        $providerContent = file_get_contents(__DIR__ . '/../Config/provider.stub');
727
728
        $guardFileContentNew = str_replace([
729
            '{{$nameSmall}}',
730
            '{{$nameSmallPlural}}'
731
        ], [
732
            "$nameSmall",
733
            "$nameSmallPlural"
734
        ], $guardContent);
735
736
        $passwordFileContentNew = str_replace('{{$nameSmallPlural}}', "$nameSmallPlural", $passwordContent);
737
738
        $providerFileContentNew = str_replace([
739
            '{{$name}}',
740
            '{{$nameSmallPlural}}'
741
        ], [
742
            "$name",
743
            "$nameSmallPlural"
744
        ], $providerContent);
745
746
        $this->insert($authConfigFile, '    \'guards\' => [', $guardFileContentNew, true);
747
748
        $this->insert($authConfigFile, '    \'passwords\' => [', $passwordFileContentNew, true);
749
750
        $this->insert($authConfigFile, '    \'providers\' => [', $providerFileContentNew, true);
751
752
        return true;
753
754
    }
755
756
    /**
757
     * Install Unauthenticated Handler.
758
     *
759
     * @return boolean
760
     */
761
    public function installUnauthenticated($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
762
    {
763
        $nameSmall = snake_case($this->getParsedNameInput());
764
        $exceptionHandlerFile = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Exceptions".DIRECTORY_SEPARATOR
765
            ."Handler.php";
766
        $exceptionHandlerFileContent = file_get_contents($exceptionHandlerFile);
767
        $exceptionHandlerFileContentNew = file_get_contents(__DIR__ . '/../Exceptions/handlerUnauthorized.stub');
768
769
770
        if (!str_contains($exceptionHandlerFileContent, 'MultiAuthUnAuthenticated')) {
771
            // replace old file
772
            $deleted = unlink($exceptionHandlerFile);
773
            if ($deleted) {
774
                file_put_contents($exceptionHandlerFile, $exceptionHandlerFileContentNew);
775
            }
776
        }
777
778
        $exceptionHandlerGuardContentNew = file_get_contents(__DIR__ . '/../Exceptions/handlerGuard.stub');
779
        $exceptionHandlerGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
780
            $exceptionHandlerGuardContentNew);
781
782
        $this->insert($exceptionHandlerFile, '        switch(array_get($exception->guards(), 0)) {',
783
            $exceptionHandlerGuardContentNew2, true);
784
785
        return true;
786
787
    }
788
789
    /**
790
     * Install Middleware.
791
     *
792
     * @return boolean
793
     */
794
795
    public function installMiddleware($is_backpack_enabled)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $is_backpack_enabled is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
796
    {
797
        $nameSmall = snake_case($this->getParsedNameInput());
798
799
        $redirectIfMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."RedirectIfAuthenticated.php";
800
        $middlewareKernelFile = $this->getHttpPath().DIRECTORY_SEPARATOR."Kernel.php";
801
802
        $redirectIfMiddlewareFileContent = file_get_contents($redirectIfMiddlewareFile);
803
804
        $redirectIfMiddlewareContentNew = file_get_contents(__DIR__ . '/../Middleware/redirectIf.stub');
805
806
        if (!str_contains($redirectIfMiddlewareFileContent, 'MultiAuthGuards')) {
807
            // replace old file
808
            $deleted = unlink($redirectIfMiddlewareFile);
809
            if ($deleted) {
810
                file_put_contents($redirectIfMiddlewareFile, $redirectIfMiddlewareContentNew);
811
            }
812
        }
813
814
        $redirectIfMiddlewareGroupContentNew = file_get_contents(__DIR__ . '/../Middleware/redirectMiddleware.stub');
815
        $redirectIfMiddlewareGuardContentNew = file_get_contents(__DIR__ . '/../Middleware/redirectMiddlewareGuard.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
816
817
        $redirectIfMiddlewareGroupContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
818
            $redirectIfMiddlewareGroupContentNew);
819
        $redirectIfMiddlewareGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
820
            $redirectIfMiddlewareGuardContentNew);
821
822
        $this->insert($middlewareKernelFile, '    protected $middlewareGroups = [',
823
            $redirectIfMiddlewareGroupContentNew2, true);
824
825
        $this->insert($redirectIfMiddlewareFile, '        switch ($guard) {',
826
            $redirectIfMiddlewareGuardContentNew2, true);
827
828
        return true;
829
830
    }
831
832
    /**
833
     * Run a SSH command.
834
     *
835
     * @param string $command      The SSH command that needs to be run
836
     * @param bool   $beforeNotice Information for the user before the command is run
837
     * @param bool   $afterNotice  Information for the user after the command is run
838
     *
839
     * @return mixed Command-line output
840
     */
841
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
842
    {
843
        if ($beforeNotice) {
844
            $this->info('### '.$beforeNotice);
845
        } else {
846
            $this->info('### Running: '.$command);
847
        }
848
        $process = new Process($command);
849
        $process->run(function ($type, $buffer) {
850
            if (Process::ERR === $type) {
851
                echo '... > '.$buffer;
852
            } else {
853
                echo 'OUT > '.$buffer;
854
            }
855
        });
856
        // executes after the command finishes
857
        if (!$process->isSuccessful()) {
858
            throw new ProcessFailedException($process);
859
        }
860
        if ($afterNotice) {
861
            $this->info('### '.$afterNotice);
862
        }
863
    }
864
865
    /**
866
     * Get the desired class name from the input.
867
     *
868
     * @return string
869
     */
870
    protected function getParsedNameInput()
871
    {
872
        return mb_strtolower(str_singular($this->getNameInput()));
873
    }
874
    /**
875
     * Get the desired class name from the input.
876
     *
877
     * @return string
878
     */
879
    protected function getNameInput()
880
    {
881
        return trim($this->argument('name'));
882
    }
883
884
    /**
885
     * Write the migration file to disk.
886
     *
887
     * @param  string  $name
888
     * @param  string  $table
889
     * @param  bool    $create
890
     * @return mixed
891
     */
892
    protected function writeMigration($name, $table, $create)
893
    {
894
        $file = pathinfo($this->creator->create(
895
            $name, $this->getMigrationPath(), $table, $create
896
        ), PATHINFO_FILENAME);
897
        $this->line("<info>Created Migration:</info> {$file}");
898
    }
899
900
    /**
901
     * Get migration path.
902
     *
903
     * @return string
904
     */
905
    protected function getMigrationPath()
906
    {
907
        return parent::getMigrationPath();
908
    }
909
910
    /**
911
     * Get Routes Provider Path.
912
     *
913
     * @return string
914
     */
915
    protected function getRouteServicesPath()
916
    {
917
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Providers'.DIRECTORY_SEPARATOR.'RouteServiceProvider.php';
918
    }
919
920
    /**
921
     * Get Routes Folder Path.
922
     *
923
     * @return string
924
     */
925
    protected function getAppFolderPath()
926
    {
927
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'app';
928
    }
929
930
    /**
931
     * Get Routes Folder Path.
932
     *
933
     * @return string
934
     */
935
    protected function getRoutesFolderPath()
936
    {
937
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'routes';
938
    }
939
940
    /**
941
     * Get Config Folder Path.
942
     *
943
     * @return string
944
     */
945
    protected function getConfigsFolderPath()
946
    {
947
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'config';
948
    }
949
950
    /**
951
     * Get Config Folder Path.
952
     *
953
     * @return string
954
     */
955
    protected function getViewsFolderPath()
956
    {
957
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'views';
958
    }
959
960
    /**
961
     * Get Controllers Path.
962
     *
963
     * @return string
964
     */
965
    protected function getControllersPath()
966
    {
967
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Controllers';
968
    }
969
970
    /**
971
     * Get Http Path.
972
     *
973
     * @return string
974
     */
975
    protected function getHttpPath()
976
    {
977
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http';
978
    }
979
980
    /**
981
     * Get Middleware Path.
982
     *
983
     * @return string
984
     */
985
    protected function getMiddlewarePath()
986
    {
987
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Middleware';
988
    }
989
990
    /**
991
     * insert text into file
992
     *
993
     * @param string $filePath
994
     * @param string $insertMarker
995
     * @param string $text
996
     * @param boolean $after
997
     *
998
     * @return integer
999
     */
1000
    public function insertIntoFile($filePath, $insertMarker, $text, $after = true) {
1001
        $contents = file_get_contents($filePath);
1002
        $new_contents = preg_replace($insertMarker,($after) ? '$0' . $text : $text . '$0', $contents);
1003
        return file_put_contents($filePath, $new_contents);
1004
    }
1005
1006
    /**
1007
     * insert text into file
1008
     *
1009
     * @param string $filePath
1010
     * @param string $keyword
1011
     * @param string $body
1012
     * @param boolean $after
1013
     *
1014
     * @return integer
1015
     */
1016
    public function insert($filePath, $keyword, $body, $after = true) {
1017
1018
        $contents = file_get_contents($filePath);
1019
        $new_contents = substr_replace($contents, PHP_EOL . $body,
1020
            ($after) ? strpos($contents, $keyword) + strlen($keyword) : strpos($contents, $keyword)
1021
            , 0);
1022
        return file_put_contents($filePath, $new_contents);
1023
    }
1024
}
1025