summaryrefslogtreecommitdiff
path: root/DomainDig/PortScanService.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-20 16:22:28 -0500
committerChristian Cleberg <[email protected]>2026-07-20 16:27:59 -0500
commitbb18197860ffdb491f010648ec903003b6e1bb65 (patch)
treee569d7cdeb1c14c7eab889cb7fac1ea9813e6efe /DomainDig/PortScanService.swift
parent083dfa723739eedd409ea8a6ae27332e48515210 (diff)
downloaddomain-dig-bb18197860ffdb491f010648ec903003b6e1bb65.tar.gz
domain-dig-bb18197860ffdb491f010648ec903003b6e1bb65.tar.bz2
domain-dig-bb18197860ffdb491f010648ec903003b6e1bb65.zip
v4.8.3: Clear SonarCloud new-code issues
Fixes the 4 reported bugs and ~97 code smells flagged in the new-code period. No behavior changes. Bugs (swift:S3923) — DomainInspectionService's confidenceFor* helpers each returned `error == nil ? .low : .low`, an inert conditional. Simplified to `return .low` and dropped the now-unused `error` parameter. Smells: - Merged 14 identical `.empty`/`.error` switch branches in DomainViewModel - Consolidated duplicate implementations (clearPresentedResults/reset, String.nonEmpty/nilIfEmpty, ExportFormat.id/fileExtension) - Extracted nested ternaries into TLSGrade.tone, EmailSecurityGrade.tone, and ChangeImpactClassification.color; removed ContentView.impactColor and the duplicate mapping in BatchResultsView - Documented empty closures and singleton inits - Marked unused protocol-conformance parameters `_` - Renamed CloudSyncTrigger.`import` to `imported` (raw value preserved) and SSLSessionDelegate's _serverTrust/_tlsMetadata - Merged nested ifs in the DER parser; flattened closure nesting in PortScanService and IntegrationService - Replaced two-case switches with if/else Left open: S107 (init parameter counts), S115 (constants mirroring DoH and ipapi JSON keys), S1075 (false positives on https:// literals), and two S117 hits on SwiftUI $binding shorthand. These want a Won't Fix resolution in SonarCloud, not a code change.
Diffstat (limited to 'DomainDig/PortScanService.swift')
-rw-r--r--DomainDig/PortScanService.swift39
1 files changed, 21 insertions, 18 deletions
diff --git a/DomainDig/PortScanService.swift b/DomainDig/PortScanService.swift
index 1f3e649..808b38a 100644
--- a/DomainDig/PortScanService.swift
+++ b/DomainDig/PortScanService.swift
@@ -89,24 +89,7 @@ struct PortScanService {
switch state {
case .ready:
connection.receive(minimumIncompleteLength: 1, maximumLength: 256) { data, _, _, error in
- guard error == nil,
- let data,
- !data.isEmpty,
- let rawBanner = String(data: data, encoding: .utf8) else {
- context.finish(with: nil)
- return
- }
-
- let printableBanner = rawBanner.filter { character in
- guard let scalar = character.unicodeScalars.first,
- character.unicodeScalars.count == 1 else {
- return false
- }
- return (32...126).contains(scalar.value)
- }
-
- let banner = String(printableBanner.prefix(80))
- context.finish(with: banner.isEmpty ? nil : banner)
+ context.finish(with: printableBanner(from: data, error: error))
}
case .failed, .cancelled:
context.finish(with: nil)
@@ -123,6 +106,26 @@ struct PortScanService {
}
}
+ private static func printableBanner(from data: Data?, error: Error?) -> String? {
+ guard error == nil,
+ let data,
+ !data.isEmpty,
+ let rawBanner = String(data: data, encoding: .utf8) else {
+ return nil
+ }
+
+ let printable = rawBanner.filter { character in
+ guard let scalar = character.unicodeScalars.first,
+ character.unicodeScalars.count == 1 else {
+ return false
+ }
+ return (32...126).contains(scalar.value)
+ }
+
+ let banner = String(printable.prefix(80))
+ return banner.isEmpty ? nil : banner
+ }
+
private static func probe(domain: String, port: UInt16) async -> PortProbeResult {
await probe(domain: domain, port: port, timeout: 1.5)
}