-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
🔍 Duplicate Code Detected: Domain Accessor Methods
*Analysis of commit *
Assignee: @copilot
Summary
The domain accessor helpers (GetAllowedDomains, GetDeniedDomains, SetAllowedDomains, SetDeniedDomains) are implemented twice—once on DomainAnalysis in the squid access log parser and again on FirewallAnalysis in the firewall log parser. The method bodies are identical, duplicating 16+ lines of code and increasing maintenance effort.
Duplication Details
Pattern: Duplicated domain accessor methods on analysis structs
- Severity: Medium
- Occurrences: 2 structs, 8 methods total
- Locations:
pkg/cli/access_log.go(lines 38-55)pkg/cli/firewall_log.go(lines 128-145)
- Code Sample:
// GetAllowedDomains returns the list of allowed domains func (a *DomainAnalysis) GetAllowedDomains() []string { return a.AllowedDomains } // SetAllowedDomains sets the list of allowed domains func (a *DomainAnalysis) SetAllowedDomains(domains []string) { a.AllowedDomains = domains }
Impact Analysis
- Maintainability: Any change to accessor behavior must be updated in both types, risking drift.
- Bug Risk: Future logic adjustments (e.g., deduping or sorting) could be missed in one copy.
- Code Bloat: Repeats four identically structured methods per struct without reuse.
Refactoring Recommendations
-
Extract shared accessor mixin
- Extract a small struct (e.g.,
DomainBuckets) that stores allowed/denied slices plus helper methods, and embed it in both analysis types. - Estimated effort: 1-2 hours; mostly mechanical refactor.
- Benefits: Single implementation, easier to evolve behavior.
- Extract a small struct (e.g.,
-
Leverage interface default impl
- Introduce helper functions that operate on any type implementing getter/setter contract, reducing per-struct boilerplate.
- Benefits: Keeps types lean without duplication.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 2
- Detection Method: Serena semantic code analysis
- Commit:
- Analysis Date: 2025-11-16
AI generated by Duplicate Code Detector
Copilot