fix logic and tests, update docker CI file
This commit is contained in:
@@ -6,20 +6,24 @@ class FeeGradeService
|
||||
{
|
||||
public function normalizeGrade(?string $grade): string
|
||||
{
|
||||
return strtoupper(trim((string) $grade));
|
||||
$normalized = strtoupper(trim((string) $grade));
|
||||
return str_replace([' ', '-'], '', $normalized);
|
||||
}
|
||||
|
||||
public function compareGrades(string $gradeA, string $gradeB): int
|
||||
{
|
||||
$valA = $this->getGradeLevel($gradeA);
|
||||
$valB = $this->getGradeLevel($gradeB);
|
||||
$normA = $this->normalizeGrade($gradeA);
|
||||
$normB = $this->normalizeGrade($gradeB);
|
||||
|
||||
$valA = $this->getGradeLevel($normA);
|
||||
$valB = $this->getGradeLevel($normB);
|
||||
|
||||
if ($valA !== $valB) {
|
||||
return $valA <=> $valB;
|
||||
}
|
||||
|
||||
preg_match('/\d+([A-Z]*)$/i', strtoupper($gradeA), $suffixA);
|
||||
preg_match('/\d+([A-Z]*)$/i', strtoupper($gradeB), $suffixB);
|
||||
preg_match('/\d+([A-Z]*)$/i', $normA, $suffixA);
|
||||
preg_match('/\d+([A-Z]*)$/i', $normB, $suffixB);
|
||||
|
||||
return strcmp($suffixA[1] ?? '', $suffixB[1] ?? '');
|
||||
}
|
||||
@@ -35,7 +39,7 @@ class FeeGradeService
|
||||
return 99;
|
||||
}
|
||||
|
||||
if (preg_match('/^(\d+)([A-Z]*)$/i', $grade, $matches)) {
|
||||
if (preg_match('/^(\d+)/', $grade, $matches)) {
|
||||
return (int) $matches[1];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user