Files
alrahma_sunday_school/app/Support/Enrollment/DeliberationDecision.php
T
root 383bbb7269
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 47s
Tests / PHPUnit (push) Successful in 1m16s
fix delebration test
2026-08-20 16:30:52 -04:00

72 lines
2.4 KiB
PHP

<?php
namespace App\Support\Enrollment;
final class DeliberationDecision
{
public const PASSED = 'PASSED';
public const REPEAT_CLASS = 'REPEAT_CLASS';
public const MAKE_UP_EXAM = 'MAKE_UP_EXAM';
public const EXPELLED = 'EXPELLED';
public const WITHDRAWN = 'WITHDRAWN';
public const DEFERRED_DECISION = 'DEFERRED_DECISION';
public const ALL = [
self::PASSED,
self::REPEAT_CLASS,
self::MAKE_UP_EXAM,
self::EXPELLED,
self::WITHDRAWN,
self::DEFERRED_DECISION,
];
public static function normalize(?string $decision): ?string
{
$value = trim((string) $decision);
if ($value === '') {
return null;
}
$key = strtoupper((string) preg_replace('/[^A-Z0-9]+/', '_', $value));
$key = trim((string) preg_replace('/_+/', '_', $key), '_');
if (in_array($key, self::ALL, true)) {
return $key;
}
$compact = strtolower((string) preg_replace('/[^a-z0-9]+/', '', strtolower($value)));
return match (true) {
in_array($compact, ['pass', 'passed', 'promote', 'promoted'], true) => self::PASSED,
str_contains($compact, 'repeat') || str_contains($compact, 'keepkg') => self::REPEAT_CLASS,
str_contains($compact, 'makeupexam') || str_contains($compact, 'makeupexamfall') || str_contains($compact, 'makeup') => self::MAKE_UP_EXAM,
str_contains($compact, 'deferred') || str_contains($compact, 'pendingdecision') => self::DEFERRED_DECISION,
str_contains($compact, 'withdraw') || str_contains($compact, 'widthrwan') => self::WITHDRAWN,
str_contains($compact, 'expel') => self::EXPELLED,
default => null,
};
}
public static function display(?string $decision): string
{
return match (self::normalize($decision) ?? $decision) {
self::PASSED => 'Passed',
self::REPEAT_CLASS => 'Repeat Class',
self::MAKE_UP_EXAM => 'Make-up Exam',
self::EXPELLED => 'Expelled',
self::WITHDRAWN => 'Withdrawn',
self::DEFERRED_DECISION => 'Deferred Decision',
default => trim((string) $decision),
};
}
public static function blocksEnrollment(?string $decision): bool
{
return in_array(self::normalize($decision), [
self::EXPELLED,
self::WITHDRAWN,
self::DEFERRED_DECISION,
], true);
}
}