diff --git a/src/Kickstart/Kickstart.php b/src/Kickstart/Kickstart.php index 451de5f..c262e42 100644 --- a/src/Kickstart/Kickstart.php +++ b/src/Kickstart/Kickstart.php @@ -45,6 +45,7 @@ public function __construct( /** * @return bool|int + * * @throws InvalidArgumentException */ public function copyDraftToProject() @@ -57,6 +58,7 @@ public function copyDraftToProject() /** * @return void + * * @throws FileNotFoundException */ public function copySeederToProject() @@ -98,6 +100,7 @@ public function deleteGenericSeeders() /** * @return string|null + * * @throws Throwable */ public function missingRequiredMigrationsMessage() diff --git a/src/Kickstart/Project.php b/src/Kickstart/Project.php index 8fecea1..f8fc1bc 100644 --- a/src/Kickstart/Project.php +++ b/src/Kickstart/Project.php @@ -27,9 +27,9 @@ public function __construct(string $basePath, bool $hasTeams) } /** - * @return string + * @return string * - * @throws InvalidArgumentException + * @throws InvalidArgumentException */ public function basePath() { diff --git a/src/Kickstart/Stub.php b/src/Kickstart/Stub.php index bc1ed6e..facead4 100644 --- a/src/Kickstart/Stub.php +++ b/src/Kickstart/Stub.php @@ -31,7 +31,7 @@ class Stub private $controllerType; /** - * @var array|array[] + * @var array */ private static array $modelNames = [ 'blog' => ['Post', 'Comment'], @@ -49,6 +49,7 @@ public function __construct(string $template, string $controllerType, bool $hasT /** * @return false|string + * * @throws InvalidArgumentException */ public function content() @@ -62,6 +63,7 @@ public function content() /** * @return 'none' | 'empty' | 'api' | 'web' + * * @throws InvalidArgumentException */ public function controllerType() @@ -92,6 +94,7 @@ public function draftPath() /** * @return string[] + * * @throws InvalidArgumentException */ public function modelNames() @@ -109,6 +112,7 @@ public function seederPath() /** * @return string + * * @throws InvalidArgumentException */ public function template() @@ -150,6 +154,7 @@ public function template() /** * @return string + * * @throws InvalidArgumentException */ private function controllerContent() @@ -169,39 +174,48 @@ private function controllerContent() return ''; } + /** + * @return string + */ private function emptyControllersContent() { - $result = "controllers:".PHP_EOL; + $result = 'controllers:'.PHP_EOL; foreach ($this->modelNames() as $model) { $result .= " {$model}:".PHP_EOL; - $result .= " resource: none".PHP_EOL; + $result .= ' resource: none'.PHP_EOL; } return $result; } + /** + * @return string + */ private function apiControllersContent() { - $result = "controllers:".PHP_EOL; + $result = 'controllers:'.PHP_EOL; foreach ($this->modelNames() as $model) { $pluralResource = str($model)->lower()->plural(); $result .= " {$model}:".PHP_EOL; - $result .= " resource: api".PHP_EOL; - $result .= " index:".PHP_EOL; + $result .= ' resource: api'.PHP_EOL; + $result .= ' index:'.PHP_EOL; $result .= " resource: 'paginate:{$pluralResource}'".PHP_EOL; } return $result; } + /** + * @return string + */ private function webControllersContent() { - $result = "controllers:".PHP_EOL; + $result = 'controllers:'.PHP_EOL; foreach ($this->modelNames() as $model) { $result .= " {$model}:".PHP_EOL; - $result .= " resource".PHP_EOL; + $result .= ' resource'.PHP_EOL; } return $result; diff --git a/src/NewCommand.php b/src/NewCommand.php index 0729749..b000493 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -154,28 +154,28 @@ protected function interact(InputInterface $input, OutputInterface $output) ) === 'Pest'); } - if (!version_compare(PHP_VERSION, '7.4.0', '>=')) { + if (! version_compare(PHP_VERSION, '7.4.0', '>=')) { $output->writeln(' WARN Kickstart options bypassed. PHP >= 7.4 is required'.PHP_EOL); return; } $kickstartTemplate = transform($input->getOption('kickstart'), Str::kebab(...)); - if (!in_array($kickstartTemplate, ['none', 'blog', 'podcast', 'phone-book'])) { + if (! in_array($kickstartTemplate, ['none', 'blog', 'podcast', 'phone-book'])) { $input->setOption('kickstart', select( label: 'Would you like to kickstart this project with a pre-defined template?', options: [ 'none' => 'None', 'blog' => 'Blog', 'podcast' => 'Podcast', - 'phone-book' => 'Phone Book' + 'phone-book' => 'Phone Book', ], default: 'none', - hint: implode(PHP_EOL." ", [ - "Eloquent Relationships Included:", - "Blog: BelongsTo, HasMany", - "Podcast: BelongsTo, HasMany, BelongsToMany", - "Phone Book: BelongsTo, 1-to-M Polymorphic, M-to-M Polymorphic" + hint: implode(PHP_EOL.' ', [ + 'Eloquent Relationships Included:', + 'Blog: BelongsTo, HasMany', + 'Podcast: BelongsTo, HasMany, BelongsToMany', + 'Phone Book: BelongsTo, 1-to-M Polymorphic, M-to-M Polymorphic', ]) )); } @@ -184,7 +184,7 @@ protected function interact(InputInterface $input, OutputInterface $output) $stack = $input->getOption('stack'); if ($input->getOption('jet') || ( - $input->getOption('breeze') && !in_array($stack, ['api', 'blade']) + $input->getOption('breeze') && ! in_array($stack, ['api', 'blade']) )) { $defaultControllerType = 'none'; } elseif ($stack === 'blade') { @@ -1098,19 +1098,21 @@ protected function pregReplaceInFile(string $pattern, string $replace, string $f * @param InputInterface $input * @param OutputInterface $output * @return void + * * @throws FileNotFoundException * @throws Throwable */ private function runKickstart(bool $ranDefaultMigrations, InputInterface $input, OutputInterface $output) { $output->writeln(''); - $seed = !$input->isInteractive() || ($ranDefaultMigrations && confirm( - label: "Run the kickstart seeder for the ".$this->kickstart->stub()->displayName()." template?", - hint: "Or, run manually: `php artisan db:seed --class=KickstartSeeder`" + $seed = ! $input->isInteractive() || ($ranDefaultMigrations && confirm( + label: 'Run the kickstart seeder for the '.$this->kickstart->stub()->displayName().' template?', + hint: 'Or, run manually: `php artisan db:seed --class=KickstartSeeder`' )); if (! $this->kickstart->copyDraftToProject()) { $output->writeln(' WARN Failed to copy draft.yaml to project. Kickstart disabled...'.PHP_EOL); + return; } @@ -1121,7 +1123,7 @@ private function runKickstart(bool $ranDefaultMigrations, InputInterface $input, $this->findComposer().' require laravel-shift/blueprint jasonmccreary/laravel-test-assertions --dev', "echo '{$projectPath}/draft.yaml' >> .gitignore", "echo '{$projectPath}/.blueprint' >> .gitignore", - $this->phpBinary()." artisan vendor:publish --tag=blueprint-config", + $this->phpBinary().' artisan vendor:publish --tag=blueprint-config', $this->phpBinary()." artisan blueprint:build {$this->kickstart->project()->draftPath()}", ]); @@ -1132,18 +1134,18 @@ private function runKickstart(bool $ranDefaultMigrations, InputInterface $input, $this->kickstart->copySeederToProject(); if ($seed) { - $this->runCommands([$this->phpBinary()." artisan migrate"], $input, $output, workingPath: $projectPath); + $this->runCommands([$this->phpBinary().' artisan migrate'], $input, $output, workingPath: $projectPath); if ($msg = $this->kickstart->missingRequiredMigrationsMessage()) { $output->writeln(' WARN '.$msg.PHP_EOL); } else { - $this->runCommands([$this->phpBinary()." artisan db:seed --class=KickstartSeeder"], $input, $output, workingPath: $projectPath); + $this->runCommands([$this->phpBinary().' artisan db:seed --class=KickstartSeeder'], $input, $output, workingPath: $projectPath); } } $this->commitChanges('Kickstart Complete', $projectPath, $input, $output); - $output->writeln(" INFO Kickstart files created 🚀.".PHP_EOL); + $output->writeln(' INFO Kickstart files created 🚀.'.PHP_EOL); } /** @@ -1152,7 +1154,7 @@ private function runKickstart(bool $ranDefaultMigrations, InputInterface $input, */ private function installApiCommand(bool $seed) { - if (!$this->usingLaravelVersionOrNewer(11, $this->kickstart->project()->basePath())) { + if (! $this->usingLaravelVersionOrNewer(11, $this->kickstart->project()->basePath())) { return null; } @@ -1160,10 +1162,10 @@ private function installApiCommand(bool $seed) return null; } - if (!$seed) { - return $this->phpBinary()." artisan install:api --without-migration-prompt"; + if (! $seed) { + return $this->phpBinary().' artisan install:api --without-migration-prompt'; } - return $this->phpBinary()." artisan install:api --no-interaction"; + return $this->phpBinary().' artisan install:api --no-interaction'; } }