Skip to content
Permalink
Browse files

opmitisation of fromReadableSize

  • Loading branch information...
ceeram committed Sep 18, 2012
1 parent 07c5102 commit 90c32add9cea115ca7c6ffc4acc6f792565898a3
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/Cake/Utility/CakeNumber.php
@@ -112,15 +112,16 @@ public static function fromReadableSize($size, $default = false) {
if (ctype_digit($size)) {
return $size * 1;
}
$units = array('KB', 'MB', 'GB', 'TB', 'PB');
foreach ($units as $i => $unit) {
if ($unit == substr($size, -2)) {
return $size * pow(1024, $i + 1);
}
$i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB'));
if ($i !== false) {
return $size * pow(1024, $i + 1);
}
if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) {
return $size * 1;
}
if ($default !== false) {
return $default;
}

0 comments on commit 90c32ad

Please sign in to comment.
You can’t perform that action at this time.