Skip to content

Commit

Permalink
fix(php): Specify the spacename duplicated in the error message
Browse files Browse the repository at this point in the history
Signed-off-by: Baptiste Fotia <[email protected]>
  • Loading branch information
zak39 committed Feb 20, 2024
1 parent d5dabd4 commit 5230f5e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/Commands/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($this->workspaceCheckService->spacenamesIsDuplicated($dataFormated)) {
throw new \Exception('Impossible to import your workspaces from the csv file. You have spacenames duplicated.');
$message = "Impossible to import your workspaces from the csv file.\n";
$message .= $this->getSpacenamesFromCsvFileDuplicated($dataFormated);
throw new \Exception($message);
}

$message = $this->getSpacenamesDuplicated($dataFormated);
Expand Down Expand Up @@ -135,6 +137,25 @@ protected function configure(): void {
parent::configure();
}

private function getSpacenamesFromCsvFileDuplicated(array $spaces): string {
$workspaceNames = [];
$message = '';

foreach ($spaces as $space) {
$workspaceNames[] = $space['workspace_name'];
}

$workspaceNamesDiff = array_values(
array_diff_assoc($workspaceNames, array_unique($workspaceNames))
);

$spacenamesFormated = array_map(fn ($spacename) => "- $spacename\n", $workspaceNamesDiff);

$message .= "The Workspace names below are duplicated:\n" . implode('', $spacenamesFormated);

return $message;
}

private function getSpacenamesDuplicated(array $dataResponse): ?string {
$workspacesAreNotExist = [];
$message = "";
Expand Down

0 comments on commit 5230f5e

Please sign in to comment.