Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit dd1b5fa

Browse files
author
atehnix
committed
Refactor make:migration command
1 parent 9e32c2f commit dd1b5fa

File tree

3 files changed

+15
-58
lines changed

3 files changed

+15
-58
lines changed

src/Console/StubsPublishCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class StubsPublishCommand extends Command
9090
'Illuminate/Routing/Console/stubs/middleware.stub',
9191
];
9292

93+
/**
94+
* Paths to migration stub files and a map of their names
95+
*
96+
* @var array
97+
*/
9398
protected $migrationStubs = [
9499
'Illuminate/Database/Migrations/stubs/blank.stub' => 'migration.blank.stub',
95100
'Illuminate/Database/Migrations/stubs/create.stub' => 'migration.create.stub',

src/Database/MigrationCreator.php

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
/**
33
* This file is part of laravel-stubs package.
44
*
5+
* @author ATehnix <[email protected]>
56
* @author Daniel Camargo <[email protected]>
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

11-
namespace ATehnix\LaravelStubs\Console;
12+
namespace ATehnix\LaravelStubs\Database;
1213

1314
use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator;
1415

@@ -25,62 +26,13 @@ class MigrationCreator extends BaseMigrationCreator
2526
protected function getStub($table, $create)
2627
{
2728
if (is_null($table)) {
28-
return $this->getBlankStub($table, $create);
29-
}
30-
return ($create) ? $this->getCreateStub($table, $create) : $this->getUpdateStub($table, $create);
31-
}
32-
33-
/**
34-
* Get blank stub
35-
*
36-
* @param $table
37-
* @param $create
38-
* @return string
39-
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
40-
*/
41-
private function getBlankStub($table, $create)
42-
{
43-
$blankStub = config('stubs.path') . '/migration.blank.stub';
44-
if (!file_exists($blankStub)) {
45-
return parent::getStub($table, $create);
46-
}
47-
48-
return $this->files->get($blankStub);
49-
}
50-
51-
/**
52-
* Get create stub
53-
*
54-
* @param $table
55-
* @param $create
56-
* @return string
57-
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
58-
*/
59-
private function getCreateStub($table, $create)
60-
{
61-
$createStub = config('stubs.path') . '/migration.create.stub';
62-
if (!file_exists($createStub)) {
63-
return parent::getStub($table, $create);
64-
}
65-
66-
return $this->files->get($createStub);
67-
}
68-
69-
/**
70-
* Get update stub
71-
*
72-
* @param $table
73-
* @param $create
74-
* @return string
75-
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
76-
*/
77-
private function getUpdateStub($table, $create)
78-
{
79-
$updateStub = config('stubs.path') . '/migration.update.stub';
80-
if (!file_exists($updateStub)) {
81-
return parent::getStub($table, $create);
29+
$stub = config('stubs.path') . '/migration.blank.stub';
30+
} else {
31+
$stub = $create
32+
? config('stubs.path') . '/migration.create.stub'
33+
: config('stubs.path') . '/migration.update.stub';
8234
}
8335

84-
return $this->files->get($updateStub);
36+
return file_exists($stub) ? $this->files->get($stub) : parent::getStub($table, $create);
8537
}
8638
}

src/Providers/ArtisanServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ATehnix\LaravelStubs\Console\ListenerMakeCommand;
2121
use ATehnix\LaravelStubs\Console\MailMakeCommand;
2222
use ATehnix\LaravelStubs\Console\MiddlewareMakeCommand;
23-
use ATehnix\LaravelStubs\Console\MigrationCreator;
2423
use ATehnix\LaravelStubs\Console\ModelMakeCommand;
2524
use ATehnix\LaravelStubs\Console\NotificationMakeCommand;
2625
use ATehnix\LaravelStubs\Console\ObserverMakeCommand;
@@ -32,6 +31,7 @@
3231
use ATehnix\LaravelStubs\Console\SeederMakeCommand;
3332
use ATehnix\LaravelStubs\Console\StubsPublishCommand;
3433
use ATehnix\LaravelStubs\Console\TestMakeCommand;
34+
use ATehnix\LaravelStubs\Database\MigrationCreator;
3535
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
3636
use Illuminate\Foundation\Providers\ArtisanServiceProvider as BaseServiceProvider;
3737

@@ -295,7 +295,7 @@ protected function registerPolicyMakeCommand()
295295
protected function registerMigrateMakeCommand()
296296
{
297297
$this->app->singleton('command.migrate.make', function ($app) {
298-
$creator = app()->make(MigrationCreator::class);
298+
$creator = $app[MigrationCreator::class];
299299
$composer = $app['composer'];
300300

301301
return new MigrateMakeCommand($creator, $composer);

0 commit comments

Comments
 (0)