Files
alrahma_sunday_school_api/app/Services/Fees/FeeGradeService.php
T
2026-03-09 16:02:30 -04:00

45 lines
1020 B
PHP

<?php
namespace App\Services\Fees;
class FeeGradeService
{
public function normalizeGrade(?string $grade): string
{
return strtoupper(trim((string) $grade));
}
public function compareGrades(string $gradeA, string $gradeB): int
{
$valA = $this->getGradeLevel($gradeA);
$valB = $this->getGradeLevel($gradeB);
if ($valA !== $valB) {
return $valA <=> $valB;
}
preg_match('/\d+([A-Z]*)$/i', strtoupper($gradeA), $suffixA);
preg_match('/\d+([A-Z]*)$/i', strtoupper($gradeB), $suffixB);
return strcmp($suffixA[1] ?? '', $suffixB[1] ?? '');
}
public function getGradeLevel(string $grade): int
{
$grade = $this->normalizeGrade($grade);
if ($grade === 'K') {
return 0;
}
if ($grade === 'Y') {
return 99;
}
if (preg_match('/^(\d+)([A-Z]*)$/i', $grade, $matches)) {
return (int) $matches[1];
}
return 999;
}
}