These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\MigrateFresh\Commands; |
||
4 | |||
5 | use DB; |
||
6 | use Illuminate\Console\Command; |
||
7 | use Illuminate\Console\ConfirmableTrait; |
||
8 | use Spatie\MigrateFresh\Events\DroppedTables; |
||
9 | use Spatie\MigrateFresh\Events\DroppingTables; |
||
10 | use Spatie\MigrateFresh\TableDroppers\TableDropper; |
||
11 | use Spatie\MigrateFresh\Exceptions\CannotDropTables; |
||
12 | |||
13 | class MigrateFresh extends Command |
||
14 | { |
||
15 | use ConfirmableTrait; |
||
16 | |||
17 | /** |
||
18 | * The console command name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $signature = 'migrate:fresh {--seed} {--force}'; |
||
23 | |||
24 | /** |
||
25 | * The console command description. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $description = 'Drop all tables from db and rebuild it using migrations.'; |
||
30 | |||
31 | /** |
||
32 | * Execute the console command. |
||
33 | * |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public function handle() |
||
37 | { |
||
38 | if (! $this->confirmToProceed()) { |
||
39 | return; |
||
40 | } |
||
41 | |||
42 | $this->info('Dropping all tables...'); |
||
43 | |||
44 | event(new DroppingTables()); |
||
45 | $this->getTableDropper()->dropAllTables(); |
||
46 | //event(new DroppedTables()); |
||
0 ignored issues
–
show
|
|||
47 | |||
48 | $this->info('Running migrations...'); |
||
49 | $this->call('migrate', ['--force' => true]); |
||
50 | |||
51 | if ($this->option('seed')) { |
||
52 | $this->info('Running seeders...'); |
||
53 | $this->call('db:seed', ['--force' => true]); |
||
54 | } |
||
55 | |||
56 | $this->comment('All done!'); |
||
57 | } |
||
58 | |||
59 | public function getTableDropper(): TableDropper |
||
60 | { |
||
61 | $driverName = DB::getDriverName(); |
||
62 | |||
63 | $dropperClass = '\\Spatie\\MigrateFresh\\TableDroppers\\'.ucfirst($driverName); |
||
64 | |||
65 | if (! class_exists($dropperClass)) { |
||
66 | throw CannotDropTables::unsupportedDbDriver($driverName); |
||
67 | } |
||
68 | |||
69 | return new $dropperClass; |
||
70 | } |
||
71 | } |
||
72 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.