Files

30 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-09-01 18:54:47 +02:00
<?php
declare(strict_types=1);
namespace App\Domain\SLA;
final class SlaThresholdClassifier
{
public const WITHIN_LIMIT = 'within_limit';
public const WARNING = 'warning';
public const CRITICAL = 'critical';
public const EXCEEDED = 'exceeded';
public function classify(float $usedHours, float $allocatedHours): string
{
if ($allocatedHours < 0) throw new \InvalidArgumentException('Allocated hours must not be negative.');
$usedHours = max(0.0, $usedHours);
if ($allocatedHours === 0.0) return $usedHours > 0.0 ? self::EXCEEDED : self::WITHIN_LIMIT;
if ($usedHours > $allocatedHours) return self::EXCEEDED;
$percentage = ($usedHours / $allocatedHours) * 100;
return $percentage >= 90.0 ? self::CRITICAL : ($percentage >= 75.0 ? self::WARNING : self::WITHIN_LIMIT);
}
public function percentage(float $usedHours, float $allocatedHours): float
{
if ($allocatedHours < 0) throw new \InvalidArgumentException('Allocated hours must not be negative.');
$usedHours = max(0.0, $usedHours);
return $allocatedHours > 0.0 ? round(($usedHours / $allocatedHours) * 100, 2) : ($usedHours > 0.0 ? 100.0 : 0.0);
}
}