ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Formatter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
28 trait Formatter
29 {
30  protected function formatSize(int $size): string
31  {
32  $size_factor = 1000;
33  $unit = match (true) {
34  $size > $size_factor * $size_factor * $size_factor => DataSize::GB,
35  $size > $size_factor * $size_factor => DataSize::MB,
36  $size > $size_factor => DataSize::KB,
37  default => DataSize::Byte,
38  };
39 
40  $size = (int) (round((float) $size / (float) $unit, 2) * (float) $unit);
41 
42  return (string) (new DataSize($size, $unit));
43  }
44 }