Skip to content

Commit

Permalink
refactor(utils): extract artist limit to constant
Browse files Browse the repository at this point in the history
- Extracted the artist limit value to a constant in the Utils class.
- Replaced hardcoded value with the constant in the Sanitizer trait.
- Improved code readability and maintainability by avoiding magic numbers.
  • Loading branch information
guanguans committed Oct 10, 2024
1 parent cac25dd commit 8837f04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/Concerns/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace App\Concerns;

use App\Support\Utils;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Number;
Expand Down Expand Up @@ -43,8 +44,8 @@ public function sanitize(array $song, string $keyword): array
"<fg=red;options=bold>$keyword</>",
collect($song['artist'])
->when(
\count($song['artist']) > 3,
static fn (Collection $artist): Collection => $artist->take(3)->push('...')
\count($song['artist']) > Utils::ARTIST_LIMIT,
static fn (Collection $artist): Collection => $artist->take(Utils::ARTIST_LIMIT)->push('...')
)
->implode(',')
);
Expand Down
6 changes: 4 additions & 2 deletions app/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

final class Utils
{
public const ARTIST_LIMIT = 3;

/**
* @throws \App\Exceptions\RuntimeException
*/
Expand Down Expand Up @@ -53,8 +55,8 @@ public static function savedPathFor(array $song, ?string $savedDir = null, strin
'%s - %s',
collect($song['artist'])
->when(
\count($song['artist']) > 3,
static fn (Collection $artist): Collection => $artist->take(3)->push('...')
\count($song['artist']) > self::ARTIST_LIMIT,
static fn (Collection $artist): Collection => $artist->take(self::ARTIST_LIMIT)->push('...')
)
->implode(','),
$song['name']
Expand Down

0 comments on commit 8837f04

Please sign in to comment.