diff --git a/src/Addon/Console/Command/WriteAddonSeeder.php b/src/Addon/Console/Command/WriteAddonSeeder.php index d0d97e6..345a2b0 100644 --- a/src/Addon/Console/Command/WriteAddonSeeder.php +++ b/src/Addon/Console/Command/WriteAddonSeeder.php @@ -1,16 +1,16 @@ - * @author Ryan Thompson + * @package defr.extension.seeder_make * - * @link http://pyrocms.com/ + * @author Denis Efremov */ class WriteAddonSeeder { @@ -43,6 +43,13 @@ class WriteAddonSeeder */ private $vendor; + /** + * The streams collection. + * + * @var StreamCollection + */ + private $streams; + /** * Create a new WriteAddonSeeder instance. * @@ -74,26 +81,16 @@ public function handle(Parser $parser, Filesystem $filesystem) $slug = ucfirst(camel_case($this->slug)); $type = ucfirst(camel_case($this->type)); $vendor = ucfirst(camel_case($this->vendor)); + $addon = $slug . $type; - $addon = $slug.$type; - $class = $addon.'Seeder'; - + $class = $addon . 'Seeder'; $namespace = "{$vendor}\\{$addon}"; + $uses = $this->getUses($namespace)->implode("\n"); + $calls = $this->getCalls()->implode("\n "); - $uses = $this->getUses($namespace)->implode("\n"); - $calls = $this->getCalls()->implode("\n "); - - $path = "{$this->path}/src/{$class}.php"; - - $template = $filesystem->get( - dirname( - dirname( - dirname( - dirname(__DIR__) - ) - ) - ).'/resources/stubs/addons/seeder.stub' - ); + $path = "{$this->path}/src/{$class}.php"; + $template = $filesystem->get(dirname(dirname(dirname(dirname(__DIR__)))) + . '/resources/stubs/addons/seeder.stub'); $filesystem->makeDirectory(dirname($path), 0755, true, true); @@ -109,14 +106,14 @@ public function handle(Parser $parser, Filesystem $filesystem) * @param string $namespace The namespace * @return Collection The uses. */ - public function getUses($namespace) + private function getUses(string $namespace) { return $this->streams->map( - function ($stream) use ($namespace) + function (StreamInterface $stream) use ($namespace) { - $name = ucfirst(str_singular($stream->getSlug())); + $entity = $this->getName($stream->getSlug()); - return "use {$namespace}\\{$name}\\{$name}Seeder;"; + return "use {$namespace}\\{$entity}\\{$entity}Seeder;"; } ); } @@ -126,14 +123,14 @@ function ($stream) use ($namespace) * * @return Collection The calls. */ - public function getCalls() + private function getCalls() { return $this->streams->map( - function ($stream) + function (StreamInterface $stream) { - $name = ucfirst(str_singular($stream->getSlug())); + $entity = $this->getName($stream->getSlug()); - return "\$this->call({$name}Seeder::class);"; + return "\$this->call({$entity}Seeder::class);"; } ); } @@ -144,7 +141,7 @@ function ($stream) * @param string $slug The slug * @return string The name. */ - public function getName($slug) + private function getName(string $slug) { return ucfirst(str_singular($slug)); } diff --git a/src/Database/Seeder/Console/SeederMakeCommand.php b/src/Database/Seeder/Console/SeederMakeCommand.php index fce5bc4..a98dc6e 100644 --- a/src/Database/Seeder/Console/SeederMakeCommand.php +++ b/src/Database/Seeder/Console/SeederMakeCommand.php @@ -12,11 +12,14 @@ use \Illuminate\Support\Composer; /** - * Class SeederMakeCommand + * Seeder make command class. + * + * @package defr.extension.seeder_make + * + * @author Denis Efremov */ class SeederMakeCommand extends \Illuminate\Console\Command { - use DispatchesJobs; /** @@ -31,7 +34,7 @@ class SeederMakeCommand extends \Illuminate\Console\Command * * @var string */ - protected $description = 'Create a new seeder class for addon'; + protected $description = 'Create a new seeder classes for addon'; /** * All streams string value @@ -43,15 +46,15 @@ class SeederMakeCommand extends \Illuminate\Console\Command /** * The Composer instance. * - * @var \Illuminate\Support\Composer + * @var Composer */ protected $composer; /** * Create a new command instance. * - * @param \Illuminate\Filesystem\Filesystem $files - * @param \Illuminate\Support\Composer $composer + * @param Filesystem $files + * @param Composer $composer * @return void */ public function __construct(Filesystem $files, Composer $composer) @@ -72,6 +75,7 @@ public function fire() { throw new \Exception('Addon could not be found.'); } + $path = $addon->getPath(); $type = $addon->getType(); $slug = $addon->getSlug(); @@ -91,6 +95,7 @@ public function fire() /* @var StreamCollection $streams */ $streams = $this->getStreams($slug); + $answers = $this->makeQuestion($streams); if (array_search($this->getAllChoice(), $answers) === false) @@ -107,11 +112,7 @@ function ($stream) use ($answers) { $slug = $stream->getSlug(); - $this->dispatch(new WriteEntitySeeder( - $addon, - $slug, - $stream->getNamespace() - )); + $this->dispatch(new WriteEntitySeeder($addon, $slug)); $singular = ucfirst(str_singular($slug)); @@ -133,7 +134,7 @@ function ($stream) use ($answers) * @throws \Exception * @return string The stream namespace. */ - public function getAddonNamespace() + private function getAddonNamespace() { $namespace = $this->argument('namespace'); @@ -151,7 +152,7 @@ public function getAddonNamespace() * @param string $slug The addon slug * @return StreamCollection */ - public function getStreams($slug) + private function getStreams($slug) { return $this->dispatch(new GetStreams($slug))->filter( function ($stream) @@ -166,7 +167,7 @@ function ($stream) * * @return string All value. */ - public function getAllChoice() + private function getAllChoice() { return $this->allChoice; } @@ -177,7 +178,7 @@ public function getAllChoice() * @param StreamCollection $streams The streams * @return array Answers */ - public function makeQuestion(StreamCollection $streams) + private function makeQuestion(StreamCollection $streams) { $choices = $streams->map( function ($stream) diff --git a/src/SeederMakeExtension.php b/src/SeederMakeExtension.php index 6084831..b14d642 100644 --- a/src/SeederMakeExtension.php +++ b/src/SeederMakeExtension.php @@ -2,20 +2,14 @@ use Anomaly\Streams\Platform\Addon\Extension\Extension; +/** + * Extension class. + * + * @package defr.extension.seeder_make + * + * @author Denis Efremov + */ class SeederMakeExtension extends Extension { - /** - * This extension provides... - * - * This should contain the dot namespace - * of the addon this extension is for followed - * by the purpose.variation of the extension. - * - * For example anomaly.module.store::gateway.stripe - * - * @var null|string - */ - protected $provides = null; - } diff --git a/src/SeederMakeExtensionServiceProvider.php b/src/SeederMakeExtensionServiceProvider.php index 60656eb..7a1f5a7 100644 --- a/src/SeederMakeExtensionServiceProvider.php +++ b/src/SeederMakeExtensionServiceProvider.php @@ -3,18 +3,16 @@ use Anomaly\Streams\Platform\Addon\AddonServiceProvider; use Defr\SeederMakeExtension\Database\Seeder\Console\SeederMakeCommand; +/** + * Extension service provider class. + * + * @package defr.extension.seeder_make + * + * @author Denis Efremov + */ class SeederMakeExtensionServiceProvider extends AddonServiceProvider { - /** - * Addon commands - * - * @var array - */ - protected $commands = [ - SeederMakeCommand::class, - ]; - /** * Register the addon */ diff --git a/src/Stream/Console/Command/WriteEntitySeeder.php b/src/Stream/Console/Command/WriteEntitySeeder.php index 56ad2a9..adc591e 100644 --- a/src/Stream/Console/Command/WriteEntitySeeder.php +++ b/src/Stream/Console/Command/WriteEntitySeeder.php @@ -1,53 +1,43 @@ - * @author Ryan Thompson + * @package defr.extension.seeder_make * - * @link http://pyrocms.com/ + * @author Denis Efremov */ class WriteEntitySeeder { - /** - * The entity slug. - * - * @var string - */ - private $slug; - /** * The addon instance. * * @var Addon */ - private $addon; + protected $addon; /** - * The entity stream namespace. + * The stream slug. * * @var string */ - private $namespace; + protected $slug; /** * Create a new WriteEntitySeeder instance. * - * @param Addon $addon + * @param Addon $addon * @param $slug - * @param $namespace */ - public function __construct(Addon $addon, $slug, $namespace) + public function __construct(Addon $addon, $slug) { - $this->slug = $slug; - $this->addon = $addon; - $this->namespace = $namespace; + $this->slug = $slug; + $this->addon = $addon; } /** @@ -58,26 +48,16 @@ public function __construct(Addon $addon, $slug, $namespace) */ public function handle(Parser $parser, Filesystem $filesystem) { - $entities = camel_case($this->slug); - - $suffix = ucfirst($entities); - $entity = str_singular($suffix); - + $entities = camel_case($this->slug); + $suffix = ucfirst($entities); + $entity = str_singular($suffix); $class = "{$entity}Seeder"; - $namespace = $this->addon->getTransformedClass("{$entity}"); $path = $this->addon->getPath("src/{$entity}/{$entity}Seeder.php"); - $template = $filesystem->get( - dirname( - dirname( - dirname( - dirname(__DIR__) - ) - ) - ).'/resources/stubs/entity/seeder.stub' - ); + $template = $filesystem->get(dirname(dirname(dirname(dirname(__DIR__)))) + . '/resources/stubs/entity/seeder.stub'); $filesystem->makeDirectory(dirname($path), 0755, true, true);