Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhavenz authored and jhavens-rcn committed Dec 26, 2024
1 parent 0ac8951 commit 11804ca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/Kickstart/Kickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(

/**
* @return bool|int
*
* @throws InvalidArgumentException
*/
public function copyDraftToProject()
Expand All @@ -57,6 +58,7 @@ public function copyDraftToProject()

/**
* @return void
*
* @throws FileNotFoundException
*/
public function copySeederToProject()
Expand Down Expand Up @@ -98,6 +100,7 @@ public function deleteGenericSeeders()

/**
* @return string|null
*
* @throws Throwable
*/
public function missingRequiredMigrationsMessage()
Expand Down
4 changes: 2 additions & 2 deletions src/Kickstart/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function __construct(string $basePath, bool $hasTeams)
}

/**
* @return string
* @return string
*
* @throws InvalidArgumentException
* @throws InvalidArgumentException
*/
public function basePath()
{
Expand Down
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
42 changes: 22 additions & 20 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(' <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: [
'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',
])
));
}
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 @@ -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(' <bg=yellow;fg=black> WARN </> Failed to copy draft.yaml to project. Kickstart disabled...'.PHP_EOL);

return;
}

Expand All @@ -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()}",
]);

Expand All @@ -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(' <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);
}

/**
Expand All @@ -1152,18 +1154,18 @@ 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;
}

if ($this->kickstart->stub()->controllerType() !== 'api') {
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';
}
}

0 comments on commit 11804ca

Please sign in to comment.