Skip to content

Commit 5230f5e

Browse files
committed
fix(php): Specify the spacename duplicated in the error message
Signed-off-by: Baptiste Fotia <[email protected]>
1 parent d5dabd4 commit 5230f5e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/Commands/Import.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
}
9999

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

104106
$message = $this->getSpacenamesDuplicated($dataFormated);
@@ -135,6 +137,25 @@ protected function configure(): void {
135137
parent::configure();
136138
}
137139

140+
private function getSpacenamesFromCsvFileDuplicated(array $spaces): string {
141+
$workspaceNames = [];
142+
$message = '';
143+
144+
foreach ($spaces as $space) {
145+
$workspaceNames[] = $space['workspace_name'];
146+
}
147+
148+
$workspaceNamesDiff = array_values(
149+
array_diff_assoc($workspaceNames, array_unique($workspaceNames))
150+
);
151+
152+
$spacenamesFormated = array_map(fn ($spacename) => "- $spacename\n", $workspaceNamesDiff);
153+
154+
$message .= "The Workspace names below are duplicated:\n" . implode('', $spacenamesFormated);
155+
156+
return $message;
157+
}
158+
138159
private function getSpacenamesDuplicated(array $dataResponse): ?string {
139160
$workspacesAreNotExist = [];
140161
$message = "";

0 commit comments

Comments
 (0)