Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,24 @@ protected function runMigrations(): void

protected function createAdminUser(string $kebabName, string $serviceKey = '', string $serviceName = ''): array
{
$adminEmail = when(empty($serviceKey), "admin@{$kebabName}.com", "admin.{$serviceKey}@{$kebabName}.com");
$isServiceAdmin = (!empty($serviceKey) && !empty($serviceName));

$adminEmail = when($isServiceAdmin, "admin.{$serviceKey}@{$kebabName}.com", "admin@{$kebabName}.com");
$defaultPassword = substr(md5(uniqid()), 0, 8);

$serviceLabel = when(!empty($serviceName), " for {$serviceName}");
$serviceLabel = when($isServiceAdmin, " for {$serviceName}");
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The when() helper on this line is missing the third parameter (default value). When $isServiceAdmin is false, this will return null instead of an empty string. This could result in the service label being null rather than empty, which may cause type inconsistencies or unexpected output.

Consider changing to:

$serviceLabel = when($isServiceAdmin, " for {$serviceName}", '');
Suggested change
$serviceLabel = when($isServiceAdmin, " for {$serviceName}");
$serviceLabel = when($isServiceAdmin, " for {$serviceName}", '');

Copilot uses AI. Check for mistakes.

$adminCredentials = [
'email' => $this->ask("Please enter admin email{$serviceLabel}", $adminEmail),
'password' => $this->ask("Please enter admin password{$serviceLabel}", $defaultPassword),
];

if ($this->authType === AuthTypeEnum::None) {
$adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", "{$serviceName} Admin");
$adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", when($isServiceAdmin, "{$serviceName} Admin", 'Admin'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move default name generation to the separate variable

$adminCredentials['role_id'] = $this->ask("Please enter admin role id{$serviceLabel}", RoleEnum::Admin->value);
}

if (empty($serviceName)) {
if (!$isServiceAdmin) {
$this->adminCredentials = $adminCredentials;
}

Expand Down