This commit is contained in:
Constantin Simonis 2024-12-05 12:15:07 +01:00
parent a574c3a89a
commit e8e45a4040
Signed by: csimonis
GPG Key ID: 758DD9C506603183

View File

@ -6,14 +6,14 @@ namespace App\Objects;
use SplFileInfo;
class DirContent
readonly class DirContent
{
private function __construct(
private readonly string $name,
private readonly int $size,
private readonly string $type,
)
{
private string $name,
private int $size,
private string $type,
private string $path,
) {
}
public static function make(SplFileInfo $fileInfo): DirContent
@ -22,6 +22,7 @@ class DirContent
$fileInfo->getBasename(),
$fileInfo->getSize() ?? 0,
$fileInfo->getType() ?? 'N/A',
$fileInfo->getPath(),
);
}
@ -44,10 +45,15 @@ class DirContent
return $this->type;
}
private function getHumanReadableSize()
public function getPath(): string
{
return $this->path;
}
private function getHumanReadableSize(): string
{
$bytes = $this->size;
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$factor = floor((strlen((string) $bytes) - 1) / 3);
return sprintf("%.1f %s", $bytes / (1024 ** $factor), $size[$factor]);