You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/TrafficNotificationThreshol...

29 lines
951 B
PHTML

<?php
namespace App\Services;
/** Quota policy for future VM metering. No proxy-user fields, resets or cleanup. */
final class TrafficNotificationThreshold
{
public static function belowLimit($remainingBytes, $totalBytes, $mode, $value): bool
{
if (!is_numeric($remainingBytes) || !is_numeric($totalBytes) || !is_numeric($value)) {
return false;
}
$remaining = max(0, (float) $remainingBytes);
$total = (float) $totalBytes;
$threshold = (float) $value;
if (!is_finite($remaining) || !is_finite($total) || !is_finite($threshold) || $threshold < 0) {
return false;
}
if ($mode === 'mb') {
return $remaining / (1024 * 1024) < $threshold;
}
if ($mode !== 'per' || $threshold > 100) {
return false;
}
$percent = $total > 0 ? $remaining / $total * 100 : 0;
return $percent < $threshold;
}
}