add more controllers and fix tests
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user