mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-07-25 17:04:06 +00:00
Mass-converts all array() literals to [] across lib/, tpl/, tst/ as discussed in #1640. PHP supports short array syntax since 5.4 and the project's required PHP version is 7.4+, so this is a pure stylistic change with no behavior impact. Also flips the StyleCI configuration so future PRs are checked against short_array_syntax instead of long_array_syntax. Per @elrido in #1640, the StyleCI swap and the mass change need to land together so no branch breaks under the wrong rule. Generated with `php-cs-fixer fix --rules=array_syntax` against the .styleci.yml finder paths. 39 files touched, 487 insertions / 487 deletions (every change is a single-token replacement). Verified: - `php -l` clean on all touched files - `phpunit` from `tst/`: 230 / 230 tests pass (with 6329 assertions), excluding `ControllerWithGcsTest` which fails on PHP 8.5 because of an unrelated upstream `google/cloud-core` deprecation. The same 14 GCS-suite errors reproduce on `master` before this change. Closes #1640
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php declare(strict_types=1);
|
|
/**
|
|
* PrivateBin
|
|
*
|
|
* a zero-knowledge paste bin
|
|
*
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
|
*/
|
|
|
|
namespace PrivateBin;
|
|
|
|
use Exception;
|
|
|
|
/**
|
|
* Filter
|
|
*
|
|
* Provides data filtering functions.
|
|
*/
|
|
class Filter
|
|
{
|
|
/**
|
|
* format a given time string into a human readable label (localized)
|
|
*
|
|
* accepts times in the format "[integer][time unit]"
|
|
*
|
|
* @access public
|
|
* @static
|
|
* @param string $time
|
|
* @throws Exception
|
|
* @return string
|
|
*/
|
|
public static function formatHumanReadableTime($time)
|
|
{
|
|
if (preg_match('/^(\d+) *(\w+)$/', $time, $matches) !== 1) {
|
|
throw new Exception("Error parsing time format '$time'", 30);
|
|
}
|
|
switch ($matches[2]) {
|
|
case 'sec':
|
|
$unit = 'second';
|
|
break;
|
|
case 'min':
|
|
$unit = 'minute';
|
|
break;
|
|
default:
|
|
$unit = rtrim($matches[2], 's');
|
|
}
|
|
return I18n::_(['%d ' . $unit, '%d ' . $unit . 's'], (int) $matches[1]);
|
|
}
|
|
|
|
/**
|
|
* format a given number of bytes in IEC 80000-13:2008 notation (localized)
|
|
*
|
|
* @access public
|
|
* @static
|
|
* @param int $size
|
|
* @return string
|
|
*/
|
|
public static function formatHumanReadableSize($size)
|
|
{
|
|
$iec = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
$i = 0;
|
|
while (($size / 1000) >= 1) {
|
|
$size = $size / 1000;
|
|
++$i;
|
|
}
|
|
return number_format($size, $i ? 2 : 0, '.', ' ') . ' ' . I18n::_($iec[$i]);
|
|
}
|
|
}
|