diff --git a/src/Console/StubsPublishCommand.php b/src/Console/StubsPublishCommand.php index 8aa34d3..1b16afc 100644 --- a/src/Console/StubsPublishCommand.php +++ b/src/Console/StubsPublishCommand.php @@ -90,6 +90,11 @@ class StubsPublishCommand extends Command 'Illuminate/Routing/Console/stubs/middleware.stub', ]; + /** + * Paths to migration stub files and a map of their names + * + * @var array + */ protected $migrationStubs = [ 'Illuminate/Database/Migrations/stubs/blank.stub' => 'migration.blank.stub', 'Illuminate/Database/Migrations/stubs/create.stub' => 'migration.create.stub', diff --git a/src/Database/MigrationCreator.php b/src/Database/MigrationCreator.php index 88b09dd..0929e1d 100644 --- a/src/Database/MigrationCreator.php +++ b/src/Database/MigrationCreator.php @@ -2,13 +2,14 @@ /** * This file is part of laravel-stubs package. * + * @author ATehnix * @author Daniel Camargo * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -namespace ATehnix\LaravelStubs\Console; +namespace ATehnix\LaravelStubs\Database; use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator; @@ -25,62 +26,13 @@ class MigrationCreator extends BaseMigrationCreator protected function getStub($table, $create) { if (is_null($table)) { - return $this->getBlankStub($table, $create); - } - return ($create) ? $this->getCreateStub($table, $create) : $this->getUpdateStub($table, $create); - } - - /** - * Get blank stub - * - * @param $table - * @param $create - * @return string - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - private function getBlankStub($table, $create) - { - $blankStub = config('stubs.path') . '/migration.blank.stub'; - if (!file_exists($blankStub)) { - return parent::getStub($table, $create); - } - - return $this->files->get($blankStub); - } - - /** - * Get create stub - * - * @param $table - * @param $create - * @return string - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - private function getCreateStub($table, $create) - { - $createStub = config('stubs.path') . '/migration.create.stub'; - if (!file_exists($createStub)) { - return parent::getStub($table, $create); - } - - return $this->files->get($createStub); - } - - /** - * Get update stub - * - * @param $table - * @param $create - * @return string - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - private function getUpdateStub($table, $create) - { - $updateStub = config('stubs.path') . '/migration.update.stub'; - if (!file_exists($updateStub)) { - return parent::getStub($table, $create); + $stub = config('stubs.path') . '/migration.blank.stub'; + } else { + $stub = $create + ? config('stubs.path') . '/migration.create.stub' + : config('stubs.path') . '/migration.update.stub'; } - return $this->files->get($updateStub); + return file_exists($stub) ? $this->files->get($stub) : parent::getStub($table, $create); } } diff --git a/src/Providers/ArtisanServiceProvider.php b/src/Providers/ArtisanServiceProvider.php index 41bb411..7b3c57b 100644 --- a/src/Providers/ArtisanServiceProvider.php +++ b/src/Providers/ArtisanServiceProvider.php @@ -20,7 +20,6 @@ use ATehnix\LaravelStubs\Console\ListenerMakeCommand; use ATehnix\LaravelStubs\Console\MailMakeCommand; use ATehnix\LaravelStubs\Console\MiddlewareMakeCommand; -use ATehnix\LaravelStubs\Console\MigrationCreator; use ATehnix\LaravelStubs\Console\ModelMakeCommand; use ATehnix\LaravelStubs\Console\NotificationMakeCommand; use ATehnix\LaravelStubs\Console\ObserverMakeCommand; @@ -32,6 +31,7 @@ use ATehnix\LaravelStubs\Console\SeederMakeCommand; use ATehnix\LaravelStubs\Console\StubsPublishCommand; use ATehnix\LaravelStubs\Console\TestMakeCommand; +use ATehnix\LaravelStubs\Database\MigrationCreator; use Illuminate\Database\Console\Migrations\MigrateMakeCommand; use Illuminate\Foundation\Providers\ArtisanServiceProvider as BaseServiceProvider; @@ -295,7 +295,7 @@ protected function registerPolicyMakeCommand() protected function registerMigrateMakeCommand() { $this->app->singleton('command.migrate.make', function ($app) { - $creator = app()->make(MigrationCreator::class); + $creator = $app[MigrationCreator::class]; $composer = $app['composer']; return new MigrateMakeCommand($creator, $composer);