Skip to content

Commit 6b915d8

Browse files
authored
Remove unnecessary self keyword (#48)
### Motivation - We want to avoid redundant code by removing unnecessary self keywords ### Modifications - Removed unnecessary self keywords ### Result - No errors, `./scripts/soundness.sh` also passed. - Follow [this reference](https://github.com/apple/swift-openapi-urlsession/blob/main/CONTRIBUTING.md#run-scriptssoundnesssh)
1 parent f81270e commit 6b915d8

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

Sources/OpenAPIURLSession/URLSessionBidirectionalStreaming/HTTPBodyOutputStreamBridge.swift

+10-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
3838

3939
deinit {
4040
debug("Output stream delegate deinit")
41-
self.outputStream.delegate = nil
41+
outputStream.delegate = nil
4242
}
4343

4444
func performAction(_ action: State.Action) {
@@ -48,7 +48,7 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
4848
case .none: return
4949
case .resumeProducer(let producerContinuation):
5050
producerContinuation.resume()
51-
performAction(self.state.resumedProducer())
51+
performAction(state.resumedProducer())
5252
case .writeBytes(let chunk): writePendingBytes(chunk)
5353
case .cancelProducerAndCloseStream(let producerContinuation):
5454
producerContinuation.resume(throwing: CancellationError())
@@ -75,31 +75,28 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
7575
self.performAction(self.state.wroteFinalChunk())
7676
}
7777
}
78-
self.performAction(self.state.startedProducerTask(task))
78+
performAction(state.startedProducerTask(task))
7979
}
8080

8181
private func writePendingBytes(_ bytesToWrite: Chunk) {
8282
dispatchPrecondition(condition: .onQueue(Self.streamQueue))
8383
precondition(!bytesToWrite.isEmpty, "\(#function) must be called with non-empty bytes")
8484
guard outputStream.streamStatus == .open else {
8585
debug("Output stream closed unexpectedly.")
86-
performAction(self.state.wroteBytes(numBytesWritten: 0, streamStillHasSpaceAvailable: false))
86+
performAction(state.wroteBytes(numBytesWritten: 0, streamStillHasSpaceAvailable: false))
8787
return
8888
}
8989
switch bytesToWrite.withUnsafeBytes({ outputStream.write($0.baseAddress!, maxLength: bytesToWrite.count) }) {
9090
case 0:
9191
debug("Output stream delegate reached end of stream when writing.")
92-
performAction(self.state.endEncountered())
92+
performAction(state.endEncountered())
9393
case -1:
9494
debug("Output stream delegate encountered error writing to stream: \(outputStream.streamError!).")
95-
performAction(self.state.errorOccurred(outputStream.streamError!))
95+
performAction(state.errorOccurred(outputStream.streamError!))
9696
case let written where written > 0:
9797
debug("Output stream delegate wrote \(written) bytes to stream.")
9898
performAction(
99-
self.state.wroteBytes(
100-
numBytesWritten: written,
101-
streamStillHasSpaceAvailable: outputStream.hasSpaceAvailable
102-
)
99+
state.wroteBytes(numBytesWritten: written, streamStillHasSpaceAvailable: outputStream.hasSpaceAvailable)
103100
)
104101
default: preconditionFailure("OutputStream.write(_:maxLength:) returned undocumented value")
105102
}
@@ -115,9 +112,9 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
115112
return
116113
}
117114
startWriterTask()
118-
case .hasSpaceAvailable: performAction(self.state.spaceBecameAvailable())
119-
case .errorOccurred: performAction(self.state.errorOccurred(stream.streamError!))
120-
case .endEncountered: performAction(self.state.endEncountered())
115+
case .hasSpaceAvailable: performAction(state.spaceBecameAvailable())
116+
case .errorOccurred: performAction(state.errorOccurred(stream.streamError!))
117+
case .endEncountered: performAction(state.endEncountered())
121118
default:
122119
debug("Output stream ignoring event: \(event).")
123120
break

Sources/OpenAPIURLSession/URLSessionTransport.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public struct URLSessionTransport: ClientTransport {
105105
public func send(_ request: HTTPRequest, body requestBody: HTTPBody?, baseURL: URL, operationID: String)
106106
async throws -> (HTTPResponse, HTTPBody?)
107107
{
108-
switch self.configuration.implementation {
108+
switch configuration.implementation {
109109
case .streaming(let requestBodyStreamBufferSize, let responseBodyStreamWatermarks):
110110
#if canImport(Darwin)
111111
guard #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) else {
@@ -193,9 +193,7 @@ extension URLRequest {
193193
}
194194
self.init(url: url)
195195
self.httpMethod = request.method.rawValue
196-
for header in request.headerFields {
197-
self.setValue(header.value, forHTTPHeaderField: header.name.canonicalName)
198-
}
196+
for header in request.headerFields { setValue(header.value, forHTTPHeaderField: header.name.canonicalName) }
199197
}
200198
}
201199

0 commit comments

Comments
 (0)