/** * @param Bytes $bytes * @return Bytes */ private static function findLargestUnitOfMeasurementPossible(Bytes $bytes) { $tb = TeraBytes::allocateBytes($bytes); if (!$tb->hasZeroBytes()) { return $tb; } $gb = GigaBytes::allocateBytes($bytes); if (!$gb->hasZeroBytes()) { return $gb; } $mb = MegaBytes::allocateBytes($bytes); if (!$mb->hasZeroBytes()) { return $mb; } $kb = KiloBytes::allocateBytes($bytes); if (!$kb->hasZeroBytes()) { return $kb; } return Bytes::allocateBytes($bytes); }