Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 30, 2024
1 parent 4adaba8 commit 5d0487e
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Models/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Number;
use Illuminate\Support\Str;

class Medium extends Model implements Contract
Expand Down Expand Up @@ -200,17 +201,7 @@ function (array $urls, string $conversion): array {
protected function formattedSize(): Attribute
{
return new Attribute(
get: static function (mixed $value, array $attributes): string {
if ($attributes['size'] === 0) {
return '0 KB';
}

$units = ['KB', 'MB', 'GB', 'TB', 'PB'];

$index = floor(log($attributes['size'], 1024));

return sprintf('%.1f %s', round($attributes['size'] / pow(1024, $index), 1), $units[$index]);
}
get: fn (): string => Number::fileSize($this->size ?: 0)
);
}

Expand Down

1 comment on commit 5d0487e

@szepeviktor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Please sign in to comment.