🔍 Duplicate Code Pattern: EvaluationResult Default Initialization
Part of duplicate code analysis: #1719
Summary
Three methods in internal/difc/evaluator.go (Evaluate, evaluateRead, evaluateWrite) each contain an identical 5-line block to initialize a default-allow EvaluationResult. Extracting this to a factory function would reduce duplication and ensure consistent defaults.
Duplication Details
Pattern: Identical EvaluationResult Struct Literal
-
Severity: Medium
-
Occurrences: 3 instances
-
Locations:
internal/difc/evaluator.go (lines ~167–171) — Evaluate method
internal/difc/evaluator.go (lines ~205–209) — evaluateRead method
internal/difc/evaluator.go (lines ~279–283) — evaluateWrite method
-
Code Sample:
// Repeated verbatim in all 3 methods:
result := &EvaluationResult{
Decision: AccessAllow,
SecrecyToAdd: []Tag{},
IntegrityToDrop: []Tag{},
}
Impact Analysis
- Maintainability: If
EvaluationResult gains a new field with a non-zero default, all 3 sites must be updated
- Bug Risk: Low currently, but grows as the struct evolves
- Code Bloat: 15 lines reducible to 3 call sites + 5-line factory
Refactoring Recommendations
- Extract a factory function
// newAllowResult returns an EvaluationResult with AccessAllow decision and empty tag slices.
func newAllowResult() *EvaluationResult {
return &EvaluationResult{
Decision: AccessAllow,
SecrecyToAdd: []Tag{},
IntegrityToDrop: []Tag{},
}
}
Replace all 3 struct literals with result := newAllowResult().
- Estimated effort: 15 minutes
- Benefits: Single authoritative default; easy to add new fields
Implementation Checklist
Parent Issue
See parent analysis report: #1719
Related to #1719
Generated by Duplicate Code Detector · ◷
🔍 Duplicate Code Pattern: EvaluationResult Default Initialization
Part of duplicate code analysis: #1719
Summary
Three methods in
internal/difc/evaluator.go(Evaluate,evaluateRead,evaluateWrite) each contain an identical 5-line block to initialize a default-allowEvaluationResult. Extracting this to a factory function would reduce duplication and ensure consistent defaults.Duplication Details
Pattern: Identical EvaluationResult Struct Literal
Severity: Medium
Occurrences: 3 instances
Locations:
internal/difc/evaluator.go(lines ~167–171) —Evaluatemethodinternal/difc/evaluator.go(lines ~205–209) —evaluateReadmethodinternal/difc/evaluator.go(lines ~279–283) —evaluateWritemethodCode Sample:
Impact Analysis
EvaluationResultgains a new field with a non-zero default, all 3 sites must be updatedRefactoring Recommendations
result := newAllowResult().Implementation Checklist
newAllowResult()private factory inevaluator.gomake test-unitto confirm no regressionsParent Issue
See parent analysis report: #1719
Related to #1719