Skip to content

Commit 4470963

Browse files
committed
Extract analysis resolution logic to helper
Add ResolveDefaultAnalyses helper method that clarifies the priority order for determining which analyses to run: first try matching on both inspection type and file extension, then fall back to file extension only, then return empty list. Makes the nested if-else logic in GetAnalysesToRun more readable by extracting it into a well-named method with explicit priority comments.
1 parent 7db2244 commit 4470963

1 file changed

Lines changed: 42 additions & 23 deletions

File tree

api/Services/AnalysisTriggerService.cs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,7 @@ InspectionRecord inspectionRecord
113113
var extension = Path.GetExtension(blobName)?.ToLowerInvariant();
114114
var inspectionType = inspectionRecord.InspectionType;
115115

116-
if (
117-
extension is not null
118-
&& inspectionType is not null
119-
&& _options.DefaultAnalysisByInspectionTypeAndExtension.TryGetValue(
120-
inspectionType,
121-
out var byExtension
122-
)
123-
&& byExtension.TryGetValue(extension, out var typedDefaults)
124-
)
125-
{
126-
requestedNames = typedDefaults;
127-
}
128-
else
129-
{
130-
requestedNames =
131-
extension is not null
132-
&& _options.DefaultAnalysisByFileExtension.TryGetValue(
133-
extension,
134-
out var defaults
135-
)
136-
? defaults
137-
: [];
138-
}
116+
requestedNames = ResolveDefaultAnalyses(inspectionType, extension);
139117
}
140118

141119
if (requestedNames.Count == 0)
@@ -418,6 +396,47 @@ private async Task CheckAndCompleteGroup(AnalysisGroup group, List<string> group
418396
}
419397
}
420398

399+
private List<string> ResolveDefaultAnalyses(string? inspectionType, string? extension)
400+
{
401+
return TryGetDefaultAnalysesByInspectionTypeAndExtension(inspectionType, extension)
402+
?? TryGetDefaultAnalysesByExtension(extension)
403+
?? [];
404+
}
405+
406+
private List<string>? TryGetDefaultAnalysesByInspectionTypeAndExtension(
407+
string? inspectionType,
408+
string? extension
409+
)
410+
{
411+
if (
412+
inspectionType is not null
413+
&& extension is not null
414+
&& _options.DefaultAnalysisByInspectionTypeAndExtension.TryGetValue(
415+
inspectionType,
416+
out var byExtension
417+
)
418+
&& byExtension.TryGetValue(extension, out var analyses)
419+
)
420+
{
421+
return analyses;
422+
}
423+
424+
return null;
425+
}
426+
427+
private List<string>? TryGetDefaultAnalysesByExtension(string? extension)
428+
{
429+
if (
430+
extension is not null
431+
&& _options.DefaultAnalysisByFileExtension.TryGetValue(extension, out var analyses)
432+
)
433+
{
434+
return analyses;
435+
}
436+
437+
return null;
438+
}
439+
421440
public async Task RerunAnalysis(Guid analysisId)
422441
{
423442
var analysis = await context

0 commit comments

Comments
 (0)