sortedRules = $this->sortRulesByPriority($rules); } /** * Evaluates all rules to determine the participant's status. * * Rules are evaluated in priority order (highest first). The first rule * that matches determines the status. Returns 'F' if no rules match. * * @param ParticipantDto $participant The participant to evaluate * * @return string The determined status code */ public function evaluateStatus(ParticipantDto $participant): string { foreach ($this->sortedRules as $rule) { if (true === $rule->evaluate($participant)) { return $rule->getStatus(); } } return self::DEFAULT_STATUS; } /** * Sorts rules by priority in descending order. * * @param ParticipantStatusRuleInterface[] $rules The rules to sort * * @return ParticipantStatusRuleInterface[] The sorted rules */ private function sortRulesByPriority(array $rules): array { usort($rules, static fn ( ParticipantStatusRuleInterface $a, ParticipantStatusRuleInterface $b, ): int => $b->getPriority() <=> $a->getPriority()); return $rules; } }