Skip to content

Commit d50de00

Browse files
committed
refactor(Sanitizer): update method signature
- Updated the method signature of the `sanitizes` method in Sanitizer.php - Changed the parameter type from array to Collection - Changed the return type from array to Collection
1 parent 955bfd1 commit d50de00

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

app/Commands/MusicCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ function () use ($timer, $keyword, &$duration): Collection {
9595
$this->reHandle();
9696
})
9797
->tap(function (Collection $songs) use (&$sanitizedSongs, $keyword, $resourceUsageFormatter, $duration): void {
98-
table($this->config['table_header'], $sanitizedSongs = $this->sanitizes($songs->all(), $keyword));
98+
table($this->config['table_header'], $sanitizedSongs = $this->sanitizes($songs, $keyword));
9999
\Laravel\Prompts\info($resourceUsageFormatter->resourceUsage($duration));
100100
})
101101
->tap(function () use (&$options, $sanitizedSongs): void {
102-
$options = collect($sanitizedSongs)
102+
$options = $sanitizedSongs
103103
->transform(static fn (array $song): string => implode(' ', Arr::except($song, [0])))
104104
->prepend($this->config['all_songs']);
105105
})

app/Concerns/HttpClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
trait HttpClientFactory
1818
{
19-
protected static ?Client $httpClient = null;
19+
protected static null|Client $httpClient = null;
2020

2121
public function createHttpClient(array $config = []): Client
2222
{

app/Concerns/Sanitizer.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@
1313
namespace App\Concerns;
1414

1515
use Illuminate\Support\Arr;
16+
use Illuminate\Support\Collection;
1617

1718
trait Sanitizer
1819
{
19-
/**
20-
* @return array<array<array-key, null|int|string>>
21-
*/
22-
public function sanitizes(array $songs, string $keyword): array
20+
public function sanitizes(Collection $songs, string $keyword): Collection
2321
{
24-
return collect($songs)
25-
->mapWithKeys(function (array $song, int $index) use ($keyword): array {
26-
$song = $this->sanitize($song, $keyword);
27-
array_unshift($song, "<fg=cyan>$index</>");
28-
29-
return [$index => $song];
30-
})
31-
->all();
22+
return $songs->mapWithKeys(function (array $song, int $index) use ($keyword): array {
23+
$song = $this->sanitize($song, $keyword);
24+
array_unshift($song, "<fg=cyan>$index</>");
25+
26+
return [$index => $song];
27+
});
3228
}
3329

3430
/**

0 commit comments

Comments
 (0)