Skip to content

Commit d522d76

Browse files
committed
Consolidate byte format logic into method
1 parent c7b27a2 commit d522d76

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/FileSize.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function subtract($sizeString)
8989
*/
9090
public function multiply($n)
9191
{
92-
$this->bytes = (int) ceil($this->bytes * $n);
92+
$this->bytes = self::byteFormat($this->bytes * $n);
9393

9494
return $this;
9595
}
@@ -243,6 +243,17 @@ private static function byteFactor($factor)
243243
return 2 ** (10 * $factor);
244244
}
245245

246+
/**
247+
* Format a numeric string into a byte count (integer).
248+
*
249+
* @param string $number A numeric string or float
250+
* @return int
251+
*/
252+
private static function byteFormat($number)
253+
{
254+
return (int) ceil($number);
255+
}
256+
246257
/**
247258
* Change the filesize unit measurement using known units.
248259
*
@@ -262,7 +273,7 @@ private function convert($size, $fromUnit, $toUnit, $precision = null)
262273

263274
// For bytes, return a rounded integer.
264275
if ($toUnit === 'B') {
265-
return (int) ceil($size);
276+
return self::byteFormat($size);
266277
}
267278

268279
return $precision ? round($size, $precision) : $size;

0 commit comments

Comments
 (0)