From eef4b6752d6b9cd820aa7c31a3cf89803777b983 Mon Sep 17 00:00:00 2001 From: Kim Ipsen Date: Tue, 10 Nov 2026 13:19:04 +0000 Subject: [PATCH] fix(night-duty): simplify the iCal token lookup (SonarCloud S3267) [skip-docs] NightFeed.FindMatchingToken now uses FirstOrDefault instead of a foreach loop; the per-candidate FixedTimeEquals comparison is unchanged. The remaining SonarCloud findings on PR #77 (S3903, S1186, S3060 on the union declaration, S8970, S107 on the feed handler) are known false positives (sonar-known-issues.md) and are left for marking in SonarCloud. Refs #67 Co-Authored-By: Claude Opus 5.5 --- .../buddy/Features/NightDuty/Types/NightFeed.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/backend/buddy/Features/NightDuty/Types/NightFeed.cs b/src/backend/buddy/Features/NightDuty/Types/NightFeed.cs index 822d5830..dcf4c9db 100644 --- a/src/backend/buddy/Features/NightDuty/Types/NightFeed.cs +++ b/src/backend/buddy/Features/NightDuty/Types/NightFeed.cs @@ -21,15 +21,8 @@ public sealed record NightFeed( { var submittedBytes = Encoding.UTF8.GetBytes(submittedTokenHash); - foreach (var info in Tokens.Values) - { - if (CryptographicOperations.FixedTimeEquals(submittedBytes, Encoding.UTF8.GetBytes(info.Hash))) - { - return info; - } - } - - return null; + return Tokens.Values.FirstOrDefault( + info => CryptographicOperations.FixedTimeEquals(submittedBytes, Encoding.UTF8.GetBytes(info.Hash))); } public static NightFeed? Rehydrate(IEnumerable events) => EventReplay.Rehydrate(events, Start, Advance);