1 | <?php |
||||
2 | |||||
3 | namespace Larafast\Fastapi\Console\Commands; |
||||
4 | |||||
5 | use Illuminate\Database\Console\Migrations\BaseCommand; |
||||
6 | use Illuminate\Database\Migrations\MigrationCreator; |
||||
7 | use Illuminate\Support\Composer; |
||||
8 | use Illuminate\Support\Str; |
||||
9 | |||||
10 | class MigrateMakeCommand extends BaseCommand |
||||
11 | { |
||||
12 | /** |
||||
13 | * The console command signature. |
||||
14 | * |
||||
15 | * @var string |
||||
16 | */ |
||||
17 | protected $signature = 'fastApi:migration {name : The name of the migration.} |
||||
18 | {--create= : The table to be created.} |
||||
19 | {--table= : The table to migrate.} |
||||
20 | {--path= : The location where the migration file should be created.} |
||||
21 | {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths.} |
||||
22 | {--fullpath : Output the full path of the migration}'; |
||||
23 | |||||
24 | /** |
||||
25 | * The console command description. |
||||
26 | * |
||||
27 | * @var string |
||||
28 | */ |
||||
29 | protected $description = 'Create a new migration file'; |
||||
30 | |||||
31 | /** |
||||
32 | * The migration creator instance. |
||||
33 | * |
||||
34 | * @var \Illuminate\Database\Migrations\MigrationCreator |
||||
35 | */ |
||||
36 | protected $creator; |
||||
37 | |||||
38 | /** |
||||
39 | * The Composer instance. |
||||
40 | * |
||||
41 | * @var \Illuminate\Support\Composer |
||||
42 | */ |
||||
43 | protected $composer; |
||||
44 | |||||
45 | /** |
||||
46 | * Create a new migration install command instance. |
||||
47 | * |
||||
48 | * @param \Illuminate\Database\Migrations\MigrationCreator $creator |
||||
49 | * @param \Illuminate\Support\Composer $composer |
||||
50 | * @return void |
||||
51 | */ |
||||
52 | public function __construct(MigrationCreator $creator, Composer $composer) |
||||
53 | { |
||||
54 | parent::__construct(); |
||||
55 | |||||
56 | $this->creator = $creator; |
||||
57 | $this->composer = $composer; |
||||
58 | } |
||||
59 | |||||
60 | /** |
||||
61 | * Execute the console command. |
||||
62 | * |
||||
63 | * @return void |
||||
64 | */ |
||||
65 | public function handle() |
||||
66 | { |
||||
67 | // It's possible for the developer to specify the tables to modify in this |
||||
68 | // schema operation. The developer may also specify if this table needs |
||||
69 | // to be freshly created so we can create the appropriate migrations. |
||||
70 | $name = Str::snake(trim($this->input->getArgument('name'))); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
71 | |||||
72 | $table = $this->input->getOption('table'); |
||||
73 | |||||
74 | $create = $this->input->getOption('create') ?: false; |
||||
75 | |||||
76 | // If no table was given as an option but a create option is given then we |
||||
77 | // will use the "create" option as the table name. This allows the devs |
||||
78 | // to pass a table name into this option as a short-cut for creating. |
||||
79 | if (! $table && is_string($create)) { |
||||
80 | $table = $create; |
||||
81 | |||||
82 | $create = true; |
||||
83 | } |
||||
84 | |||||
85 | // Next, we will attempt to guess the table name if this the migration has |
||||
86 | // "create" in the name. This will allow us to provide a convenient way |
||||
87 | // of creating migrations that create new tables for the application. |
||||
88 | if (! $table) { |
||||
89 | [$table, $create] = TableGuesser::guess($name); |
||||
0 ignored issues
–
show
The type
Larafast\Fastapi\Console\Commands\TableGuesser 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
90 | } |
||||
91 | |||||
92 | // Now we are ready to write the migration out to disk. Once we've written |
||||
93 | // the migration out, we will dump-autoload for the entire framework to |
||||
94 | // make sure that the migrations are registered by the class loaders. |
||||
95 | $this->writeMigration($name, $table, $create); |
||||
96 | |||||
97 | $this->composer->dumpAutoloads(); |
||||
98 | } |
||||
99 | |||||
100 | /** |
||||
101 | * Write the migration file to disk. |
||||
102 | * |
||||
103 | * @param string $name |
||||
104 | * @param string $table |
||||
105 | * @param bool $create |
||||
106 | * @return string |
||||
107 | */ |
||||
108 | protected function writeMigration($name, $table, $create) |
||||
109 | { |
||||
110 | $file = $this->creator->create( |
||||
111 | $name, $this->getMigrationPath(), $table, $create |
||||
112 | ); |
||||
113 | |||||
114 | if (! $this->option('fullpath')) { |
||||
115 | $file = pathinfo($file, PATHINFO_FILENAME); |
||||
116 | } |
||||
117 | |||||
118 | $this->line("<info>Created Migration:</info> {$file}"); |
||||
119 | } |
||||
120 | |||||
121 | /** |
||||
122 | * Get migration path (either specified by '--path' option or default location). |
||||
123 | * |
||||
124 | * @return string |
||||
125 | */ |
||||
126 | protected function getMigrationPath() |
||||
127 | { |
||||
128 | if (! is_null($targetPath = $this->input->getOption('path'))) { |
||||
129 | return ! $this->usingRealPath() |
||||
0 ignored issues
–
show
|
|||||
130 | ? $this->laravel->basePath().'/'.$targetPath |
||||
0 ignored issues
–
show
Are you sure
$targetPath of type boolean|string|string[] can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
131 | : $targetPath; |
||||
132 | } |
||||
133 | |||||
134 | return parent::getMigrationPath(); |
||||
135 | } |
||||
136 | |||||
137 | /** |
||||
138 | * Determine if the given path(s) are pre-resolved "real" paths. |
||||
139 | * |
||||
140 | * @return bool |
||||
141 | */ |
||||
142 | protected function usingRealPath() |
||||
143 | { |
||||
144 | return $this->input->hasOption('realpath') && $this->option('realpath'); |
||||
145 | } |
||||
146 | } |
||||
147 |