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

Commit

Permalink
Refactor make:migration command
Browse files Browse the repository at this point in the history
  • Loading branch information
atehnix committed Sep 6, 2018
1 parent 9e32c2f commit dd1b5fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 58 deletions.
5 changes: 5 additions & 0 deletions src/Console/StubsPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
64 changes: 8 additions & 56 deletions src/Database/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/**
* This file is part of laravel-stubs package.
*
* @author ATehnix <[email protected]>
* @author Daniel Camargo <[email protected]>
*
* 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;

Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dd1b5fa

Please sign in to comment.