Skip to content

Commit

Permalink
Split out output handler to void handle method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 22, 2024
1 parent 6edbf35 commit 9c01ea8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ protected function handleInteractivePublish(string $selected): void
$choices = $publisher->getFileChoices();

$selectedFiles = multiselect('Select the files you want to publish (CTRL+A to toggle all)', $choices, [], 10, 'required', hint: 'Navigate with arrow keys, space to select, enter to confirm.');
$publisher->handle($selectedFiles);

$this->infoComment($publisher->handle($selectedFiles));
$this->infoComment($publisher->formatOutput($selectedFiles));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ public function getFileChoices(): array
}

/** @param array<string> $selectedFiles */
public function handle(array $selectedFiles): string
public function handle(array $selectedFiles): void
{
$filesToPublish = $this->filterPublishableFiles($selectedFiles);

$this->publishFiles($filesToPublish);

return sprintf('Published files [%s]', $this->getPublishedFilesForOutput($selectedFiles));
}

/** @return array{string, string} */
Expand Down Expand Up @@ -88,9 +86,11 @@ protected function publishFiles(array $selectedFiles): void
}
}

protected function getPublishedFilesForOutput(array $selectedFiles): string
public function formatOutput(array $selectedFiles): string
{
return collect($selectedFiles)->map(fn (string $file): string => $this->pathRelativeToDirectory($file, $this->sourceDirectory))->implode(', ');
$publishedFiles = collect($selectedFiles)->map(fn (string $file): string => $this->pathRelativeToDirectory($file, $this->sourceDirectory))->implode(', ');

return sprintf('Published files [%s]', $publishedFiles);
}

protected function pathRelativeToDirectory(string $source, string $directory): string
Expand Down

0 comments on commit 9c01ea8

Please sign in to comment.