!$this->isTree($item)); } public function isTree($value): bool { if (!$value) { return false; } return $value instanceof Tree; } public function getCommitish(string $hash, string $path): string { return $hash.'/'.$path; } public function getParent(string $path): string { $parent = dirname($path); if ('.' == $parent) { return ''; } return $parent; } public function getBreadcrumbs(Blob $blob): array { $breadcrumbs = []; $parts = explode('/', $blob->getName()); $previousPart = ''; foreach ($parts as $index => $part) { $previousPart .= (0 == $index ? '' : '/').$part; $breadcrumbs[] = [ 'name' => $part, 'commitish' => $this->getCommitish($blob->getHash(), $previousPart), ]; } return $breadcrumbs; } public function formatFileSize($value = null): string { if (!$value) { return '0 B'; } $units = ['B', 'KB', 'MB', 'GB', 'TB']; $pow = floor(log($value) / log(1024)); $pow = min($pow, count($units) - 1); $value /= 1024 ** $pow; return (string) round($value, 2).' '.$units[$pow]; } }