diff --git a/src/Commands/Database/FactoryMakeCommand.php b/src/Commands/Database/FactoryMakeCommand.php index 94ce095..835033b 100644 --- a/src/Commands/Database/FactoryMakeCommand.php +++ b/src/Commands/Database/FactoryMakeCommand.php @@ -24,6 +24,6 @@ class FactoryMakeCommand extends MakeFactory */ protected function resolveDirectory() { - return $this->getDirInput() . '/database/factories/'; + return $this->getDirInput().'/database/factories/'; } } diff --git a/src/Commands/Database/MigrationMakeCommand.php b/src/Commands/Database/MigrationMakeCommand.php index a9a6e79..4424180 100644 --- a/src/Commands/Database/MigrationMakeCommand.php +++ b/src/Commands/Database/MigrationMakeCommand.php @@ -26,57 +26,57 @@ class MigrationMakeCommand extends MakeMigration * * @var string */ - protected $signature = null; - - /** - * Create a new migration install command instance. - * - * @param Illuminate\Filesystem\Filesystem $creator - * @param \Illuminate\Database\Migrations\MigrationCreator $creator - * @param \Illuminate\Support\Composer $composer - * @return void - */ - public function __construct(Filesystem $files, MigrationCreator $creator, Composer $composer) - { - parent::__construct($creator, $composer); - - $this->files = $files; - } - - /** - * Get migration path (either specified by '--path' option or default location). - * - * @return string - */ - protected function getMigrationPath() - { - $path = $this->basePath() . 'database/migrations'; - - if (!is_null($targetPath = $this->input->getOption('path'))) { - $path = !$this->usingRealPath() - ? $this->basePath() . $targetPath + protected $signature = null; + + /** + * Create a new migration install command instance. + * + * @param Illuminate\Filesystem\Filesystem $creator + * @param \Illuminate\Database\Migrations\MigrationCreator $creator + * @param \Illuminate\Support\Composer $composer + * @return void + */ + public function __construct(Filesystem $files, MigrationCreator $creator, Composer $composer) + { + parent::__construct($creator, $composer); + + $this->files = $files; + } + + /** + * Get migration path (either specified by '--path' option or default location). + * + * @return string + */ + protected function getMigrationPath() + { + $path = $this->basePath().'database/migrations'; + + if (! is_null($targetPath = $this->input->getOption('path'))) { + $path = ! $this->usingRealPath() + ? $this->basePath().$targetPath : $targetPath; } - $this->makeDirectory($path . '/some_migration.php'); + $this->makeDirectory($path.'/some_migration.php'); - return $path; - } + return $path; + } - /** - * Build the directory for the class if necessary. - * - * @param string $path - * @return string - */ - protected function makeDirectory($path) - { - if (!$this->files->isDirectory(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0777, true, true); - } + /** + * Build the directory for the class if necessary. + * + * @param string $path + * @return string + */ + protected function makeDirectory($path) + { + if (! $this->files->isDirectory(dirname($path))) { + $this->files->makeDirectory(dirname($path), 0777, true, true); + } - return $path; - } + return $path; + } /** * Adds additional options to the command. @@ -95,4 +95,4 @@ protected function additionalOptions() ['realpath', null, InputOption::VALUE_REQUIRED, 'Indicate any provided migration file paths are pre - resolved absolute paths'], ]; } -} \ No newline at end of file +} diff --git a/src/Commands/Foundation/EventMakeCommand.php b/src/Commands/Foundation/EventMakeCommand.php index b39331f..934a768 100644 --- a/src/Commands/Foundation/EventMakeCommand.php +++ b/src/Commands/Foundation/EventMakeCommand.php @@ -24,6 +24,6 @@ class EventMakeCommand extends MakeEvent */ protected function resolveDirectory() { - return $this->getDirInput() . '/src'; + return $this->getDirInput().'/src'; } } diff --git a/src/Commands/Foundation/ModelMakeCommand.php b/src/Commands/Foundation/ModelMakeCommand.php index 2641195..a30c2e9 100644 --- a/src/Commands/Foundation/ModelMakeCommand.php +++ b/src/Commands/Foundation/ModelMakeCommand.php @@ -2,7 +2,6 @@ namespace Naoray\LaravelPackageMaker\Commands\Foundation; -use Symfony\Component\Console\Input\InputOption; use Naoray\LaravelPackageMaker\Traits\HasNameAttribute; use Naoray\LaravelPackageMaker\Traits\CreatesPackageStubs; use Illuminate\Foundation\Console\ModelMakeCommand as MakeModel; @@ -25,59 +24,59 @@ class ModelMakeCommand extends MakeModel */ protected function resolveDirectory() { - return $this->getDirInput() . 'src'; - } + return $this->getDirInput().'src'; + } - /** - * Create a model factory for the model. - * - * @return void - */ - protected function createFactory() - { - $factory = studly_case(class_basename($this->argument('name'))); + /** + * Create a model factory for the model. + * + * @return void + */ + protected function createFactory() + { + $factory = studly_case(class_basename($this->argument('name'))); - $this->call('make:package:factory', [ - 'name' => "{$factory}Factory", - '--model' => $this->argument('name'), - '--namespace' => $this->rootNamespace(), - '--dir' => $this->basePath(), - ]); - } + $this->call('make:package:factory', [ + 'name' => "{$factory}Factory", + '--model' => $this->argument('name'), + '--namespace' => $this->rootNamespace(), + '--dir' => $this->basePath(), + ]); + } - /** - * Create a migration file for the model. - * - * @return void - */ - protected function createMigration() - { - $table = str_plural(snake_case(class_basename($this->argument('name')))); + /** + * Create a migration file for the model. + * + * @return void + */ + protected function createMigration() + { + $table = str_plural(snake_case(class_basename($this->argument('name')))); - $this->call('make:package:migration', [ - 'name' => "create_{$table}_table", - '--create' => $table, - '--namespace' => $this->rootNamespace(), - '--dir' => $this->basePath(), - ]); - } + $this->call('make:package:migration', [ + 'name' => "create_{$table}_table", + '--create' => $table, + '--namespace' => $this->rootNamespace(), + '--dir' => $this->basePath(), + ]); + } - /** - * Create a controller for the model. - * - * @return void - */ - protected function createController() - { - $controller = studly_case(class_basename($this->argument('name'))); + /** + * Create a controller for the model. + * + * @return void + */ + protected function createController() + { + $controller = studly_case(class_basename($this->argument('name'))); - $modelName = $this->qualifyClass($this->getNameInput()); + $modelName = $this->qualifyClass($this->getNameInput()); - $this->call('make:packae:controller', [ - 'name' => "{$controller}Controller", - '--model' => $this->option('resource') ? $modelName : null, - '--namespace' => $this->rootNamespace(), - '--dir' => $this->basePath(), - ]); - } + $this->call('make:packae:controller', [ + 'name' => "{$controller}Controller", + '--model' => $this->option('resource') ? $modelName : null, + '--namespace' => $this->rootNamespace(), + '--dir' => $this->basePath(), + ]); + } } diff --git a/src/Commands/Foundation/PolicyMakeCommand.php b/src/Commands/Foundation/PolicyMakeCommand.php index da424f9..e245a7c 100644 --- a/src/Commands/Foundation/PolicyMakeCommand.php +++ b/src/Commands/Foundation/PolicyMakeCommand.php @@ -2,71 +2,70 @@ namespace Naoray\LaravelPackageMaker\Commands\Foundation; -use Symfony\Component\Console\Input\InputOption; use Naoray\LaravelPackageMaker\Traits\HasNameAttribute; use Naoray\LaravelPackageMaker\Traits\CreatesPackageStubs; use Illuminate\Foundation\Console\PolicyMakeCommand as MakePolicy; class PolicyMakeCommand extends MakePolicy { - use CreatesPackageStubs, HasNameAttribute; - - /** - * The console command name. - * - * @var string - */ - protected $name = 'make:package:policy'; - - /** - * Get the destination class path. - * - * @return string - */ - protected function resolveDirectory() - { - return $this->getDirInput() . '/src'; - } - - /** - * Replace the model for the given stub. - * - * @param string $stub - * @param string $model - * @return string - */ - protected function replaceModel($stub, $model) - { - $model = str_replace('/', '\\', $model); - - $namespaceModel = $this->rootNamespace() . '\\' . $model; - - if (starts_with($model, '\\')) { - $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); - } else { - $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub); - } - - $stub = str_replace( - "use {$namespaceModel};\nuse {$namespaceModel};", - "use {$namespaceModel};", - $stub - ); - - $model = class_basename(trim($model, '\\')); - - $dummyUser = class_basename(config('auth.providers.users.model')); - - $dummyModel = camel_case($model) === 'user' ? 'model' : $model; - - $stub = str_replace('DocDummyModel', snake_case($dummyModel, ' '), $stub); - - $stub = str_replace('DummyModel', $model, $stub); - - $stub = str_replace('dummyModel', camel_case($dummyModel), $stub); - - $stub = str_replace('DummyUser', $dummyUser, $stub); - - return str_replace('DocDummyPluralModel', snake_case(str_plural($dummyModel), ' '), $stub); - } + use CreatesPackageStubs, HasNameAttribute; + + /** + * The console command name. + * + * @var string + */ + protected $name = 'make:package:policy'; + + /** + * Get the destination class path. + * + * @return string + */ + protected function resolveDirectory() + { + return $this->getDirInput().'/src'; + } + + /** + * Replace the model for the given stub. + * + * @param string $stub + * @param string $model + * @return string + */ + protected function replaceModel($stub, $model) + { + $model = str_replace('/', '\\', $model); + + $namespaceModel = $this->rootNamespace().'\\'.$model; + + if (starts_with($model, '\\')) { + $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); + } else { + $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub); + } + + $stub = str_replace( + "use {$namespaceModel};\nuse {$namespaceModel};", + "use {$namespaceModel};", + $stub + ); + + $model = class_basename(trim($model, '\\')); + + $dummyUser = class_basename(config('auth.providers.users.model')); + + $dummyModel = camel_case($model) === 'user' ? 'model' : $model; + + $stub = str_replace('DocDummyModel', snake_case($dummyModel, ' '), $stub); + + $stub = str_replace('DummyModel', $model, $stub); + + $stub = str_replace('dummyModel', camel_case($dummyModel), $stub); + + $stub = str_replace('DummyUser', $dummyUser, $stub); + + return str_replace('DocDummyPluralModel', snake_case(str_plural($dummyModel), ' '), $stub); + } } diff --git a/src/Commands/Foundation/RuleMakeCommand.php b/src/Commands/Foundation/RuleMakeCommand.php index 3925c44..e727381 100644 --- a/src/Commands/Foundation/RuleMakeCommand.php +++ b/src/Commands/Foundation/RuleMakeCommand.php @@ -8,22 +8,22 @@ class RuleMakeCommand extends MakeRule { - use CreatesPackageStubs, HasNameAttribute; + use CreatesPackageStubs, HasNameAttribute; - /** - * The console command name. - * - * @var string - */ - protected $name = 'make:package:rule'; + /** + * The console command name. + * + * @var string + */ + protected $name = 'make:package:rule'; - /** - * Get the destination class path. - * - * @return string - */ - protected function resolveDirectory() - { - return $this->getDirInput() . '/src'; - } + /** + * Get the destination class path. + * + * @return string + */ + protected function resolveDirectory() + { + return $this->getDirInput().'/src'; + } } diff --git a/src/Commands/Routing/ControllerMakeCommand.php b/src/Commands/Routing/ControllerMakeCommand.php index 2170ec5..bfc4874 100644 --- a/src/Commands/Routing/ControllerMakeCommand.php +++ b/src/Commands/Routing/ControllerMakeCommand.php @@ -24,80 +24,80 @@ class ControllerMakeCommand extends MakeController */ protected function resolveDirectory() { - return $this->getDirInput() . 'src'; - } + return $this->getDirInput().'src'; + } - /** - * Build the replacements for a parent controller. - * - * @return array - */ - protected function buildParentReplacements() - { - $parentModelClass = $this->parseModel($this->option('parent')); + /** + * Build the replacements for a parent controller. + * + * @return array + */ + protected function buildParentReplacements() + { + $parentModelClass = $this->parseModel($this->option('parent')); - if (!class_exists($parentModelClass)) { - if ($this->confirm("A {$parentModelClass} model does not exist. Do you want to generate it?", true)) { - $this->call('make:package:model', [ - 'name' => $parentModelClass, - '--namespace' => $this->rootNamespace(), - '--dir' => $this->basePath(), - ]); - } - } + if (! class_exists($parentModelClass)) { + if ($this->confirm("A {$parentModelClass} model does not exist. Do you want to generate it?", true)) { + $this->call('make:package:model', [ + 'name' => $parentModelClass, + '--namespace' => $this->rootNamespace(), + '--dir' => $this->basePath(), + ]); + } + } - return [ - 'ParentDummyFullModelClass' => $parentModelClass, - 'ParentDummyModelClass' => class_basename($parentModelClass), - 'ParentDummyModelVariable' => lcfirst(class_basename($parentModelClass)), - ]; - } + return [ + 'ParentDummyFullModelClass' => $parentModelClass, + 'ParentDummyModelClass' => class_basename($parentModelClass), + 'ParentDummyModelVariable' => lcfirst(class_basename($parentModelClass)), + ]; + } - /** - * Build the model replacement values. - * - * @param array $replace - * @return array - */ - protected function buildModelReplacements(array $replace) - { - $modelClass = $this->parseModel($this->option('model')); + /** + * Build the model replacement values. + * + * @param array $replace + * @return array + */ + protected function buildModelReplacements(array $replace) + { + $modelClass = $this->parseModel($this->option('model')); - if (!class_exists($modelClass)) { - if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) { - $this->call('make:package:model', [ - 'name' => $modelClass, - '--namespace' => $this->rootNamespace(), - '--dir' => $this->basePath(), - ]); - } - } + if (! class_exists($modelClass)) { + if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) { + $this->call('make:package:model', [ + 'name' => $modelClass, + '--namespace' => $this->rootNamespace(), + '--dir' => $this->basePath(), + ]); + } + } - return array_merge($replace, [ - 'DummyFullModelClass' => $modelClass, - 'DummyModelClass' => class_basename($modelClass), - 'DummyModelVariable' => lcfirst(class_basename($modelClass)), - ]); - } + return array_merge($replace, [ + 'DummyFullModelClass' => $modelClass, + 'DummyModelClass' => class_basename($modelClass), + 'DummyModelVariable' => lcfirst(class_basename($modelClass)), + ]); + } - /** - * Get the fully-qualified model class name. - * - * @param string $model - * @return string - */ - protected function parseModel($model) - { - if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { - throw new InvalidArgumentException('Model name contains invalid characters.'); - } + /** + * Get the fully-qualified model class name. + * + * @param string $model + * @return string + */ + protected function parseModel($model) + { + if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { + throw new InvalidArgumentException('Model name contains invalid characters.'); + } - $model = trim(str_replace('/', '\\', $model), '\\'); + $model = trim(str_replace('/', '\\', $model), '\\'); - if (!starts_with($model, $rootNamespace = $this->rootNamespace()) && !starts_with($model, $this->laravel->getNamespace())) { - $model = $rootNamespace . '\\' . $model; - } + if (! starts_with($model, $rootNamespace = $this->rootNamespace()) && ! starts_with($model, $this->laravel->getNamespace())) { + $model = $rootNamespace.'\\'.$model; + } - return $model; - } + return $model; + } } diff --git a/src/LaravelPackageMakerServiceProvider.php b/src/LaravelPackageMakerServiceProvider.php index f5e5059..407f93c 100644 --- a/src/LaravelPackageMakerServiceProvider.php +++ b/src/LaravelPackageMakerServiceProvider.php @@ -8,20 +8,20 @@ use Naoray\LaravelPackageMaker\Commands\Foundation\JobMakeCommand; use Naoray\LaravelPackageMaker\Commands\Package\ReadmeMakeCommand; use Naoray\LaravelPackageMaker\Commands\Package\TravisMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Foundation\MailMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\RuleMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\TestMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Foundation\MailMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Package\LicenseMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Package\StyleciMakeCommand; use Naoray\LaravelPackageMaker\Commands\Package\CodecovMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Package\LicenseMakeCommand; use Naoray\LaravelPackageMaker\Commands\Package\PhpunitMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Package\BaseTestMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Package\StyleciMakeCommand; use Naoray\LaravelPackageMaker\Commands\Database\FactoryMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\EventMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Package\ComposerMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\ModelMakeCommand; -use Naoray\LaravelPackageMaker\Commands\Package\GitignoreMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Package\BaseTestMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Package\ComposerMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\PolicyMakeCommand; +use Naoray\LaravelPackageMaker\Commands\Package\GitignoreMakeCommand; use Naoray\LaravelPackageMaker\Commands\Database\MigrationMakeCommand; use Naoray\LaravelPackageMaker\Commands\Routing\ControllerMakeCommand; use Naoray\LaravelPackageMaker\Commands\Foundation\ProviderMakeCommand; diff --git a/src/Traits/CreatesPackageStubs.php b/src/Traits/CreatesPackageStubs.php index 0047ccb..581a2d2 100644 --- a/src/Traits/CreatesPackageStubs.php +++ b/src/Traits/CreatesPackageStubs.php @@ -32,12 +32,12 @@ protected function getPath($name) /** * Get Packages base Path. - * + * * @return string */ protected function basePath() { - return base_path() . '/' . $this->resolveDirectory(); + return base_path().'/'.$this->resolveDirectory(); } /**