Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhavens-rcn committed Dec 26, 2024
1 parent 0ac8951 commit 39aa330
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
30 changes: 22 additions & 8 deletions src/Kickstart/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Stub
private $controllerType;

/**
* @var array|array[]
* @var array<string, string[]>
*/
private static array $modelNames = [
'blog' => ['Post', 'Comment'],
Expand All @@ -49,6 +49,7 @@ public function __construct(string $template, string $controllerType, bool $hasT

/**
* @return false|string
*
* @throws InvalidArgumentException
*/
public function content()
Expand All @@ -62,6 +63,7 @@ public function content()

/**
* @return 'none' | 'empty' | 'api' | 'web'
*
* @throws InvalidArgumentException
*/
public function controllerType()
Expand Down Expand Up @@ -92,6 +94,7 @@ public function draftPath()

/**
* @return string[]
*
* @throws InvalidArgumentException
*/
public function modelNames()
Expand All @@ -109,6 +112,7 @@ public function seederPath()

/**
* @return string
*
* @throws InvalidArgumentException
*/
public function template()
Expand Down Expand Up @@ -150,6 +154,7 @@ public function template()

/**
* @return string
*
* @throws InvalidArgumentException
*/
private function controllerContent()
Expand All @@ -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;
Expand Down
33 changes: 17 additions & 16 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ 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(' <bg=yellow;fg=black> 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: [
Expand All @@ -172,10 +172,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
],
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"
'Eloquent Relationships Included:',
'Blog: BelongsTo, HasMany',
'Podcast: BelongsTo, HasMany, BelongsToMany',
'Phone Book: BelongsTo, 1-to-M Polymorphic, M-to-M Polymorphic'
])
));
}
Expand All @@ -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') {
Expand Down Expand Up @@ -1105,8 +1105,8 @@ private function runKickstart(bool $ranDefaultMigrations, InputInterface $input,
{
$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`"
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()) {
Expand All @@ -1121,7 +1121,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()}",
]);

Expand All @@ -1132,38 +1132,39 @@ 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(' <bg=yellow;fg=black> 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(" <bg=blue;fg=white> INFO </> Kickstart files created 🚀.".PHP_EOL);
$output->writeln(' <bg=blue;fg=white> INFO </> Kickstart files created 🚀.'.PHP_EOL);
}

/**
* @param bool $seed
*
* @return string|null
*/
private function installApiCommand(bool $seed)
{
if (!$this->usingLaravelVersionOrNewer(11, $this->kickstart->project()->basePath())) {
if (! $this->usingLaravelVersionOrNewer(11, $this->kickstart->project()->basePath())) {
return null;
}

if ($this->kickstart->stub()->controllerType() !== 'api') {
return null;
}

if (!$seed) {
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';
}
}

0 comments on commit 39aa330

Please sign in to comment.