Skip to content

Commit 508a9ae

Browse files
committed
Resolve SwiftLint 'line_length' warnings.
1 parent 2e8c9b5 commit 508a9ae

12 files changed

+141
-47
lines changed

Sources/ObjectiveC.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ import Foundation
1414
}
1515

1616
func subscribeToPresenceChannel(channelName: String) -> PusherPresenceChannel {
17-
return self.subscribeToPresenceChannel(channelName: channelName, auth: nil, onMemberAdded: nil, onMemberRemoved: nil)
17+
return self.subscribeToPresenceChannel(channelName: channelName,
18+
auth: nil,
19+
onMemberAdded: nil,
20+
onMemberRemoved: nil)
1821
}
1922

2023
func subscribeToPresenceChannel(
2124
channelName: String,
2225
onMemberAdded: ((PusherPresenceChannelMember) -> Void)? = nil,
2326
onMemberRemoved: ((PusherPresenceChannelMember) -> Void)? = nil
2427
) -> PusherPresenceChannel {
25-
return self.subscribeToPresenceChannel(channelName: channelName, auth: nil, onMemberAdded: onMemberAdded, onMemberRemoved: onMemberRemoved)
28+
return self.subscribeToPresenceChannel(channelName: channelName,
29+
auth: nil,
30+
onMemberAdded: onMemberAdded,
31+
onMemberRemoved: onMemberRemoved)
2632
}
2733

2834
convenience init(withAppKey key: String, options: PusherClientOptions) {

Sources/PusherChannel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ open class PusherChannel: NSObject {
173173
open func trigger(eventName: String, data: Any) {
174174
if PusherEncryptionHelpers.isEncryptedChannel(channelName: self.name) {
175175
let error = """
176-
ERROR: Client events are not supported on encrypted channels: '\(self.name)'. Client event '\(eventName)' will not be sent.
176+
ERROR: Client events are not supported on encrypted channels: '\(self.name)'. \
177+
Client event '\(eventName)' will not be sent.
177178
"""
178179
print(error)
179180
return

Sources/PusherConnection.swift

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ import Starscream
4343
let reachability = try? Reachability()
4444
reachability?.whenReachable = { [weak self] reachability in
4545
guard let self = self else {
46-
print("Your Pusher instance has probably become deallocated. See https://github.com/pusher/pusher-websocket-swift/issues/109 for more information")
46+
print("""
47+
Your Pusher instance has probably become deallocated. \
48+
See https://github.com/pusher/pusher-websocket-swift/issues/109 \
49+
for more information
50+
""")
4751
return
4852
}
4953

@@ -72,7 +76,11 @@ import Starscream
7276
}
7377
reachability?.whenUnreachable = { [weak self] reachability in
7478
guard let self = self else {
75-
print("Your Pusher instance has probably become deallocated. See https://github.com/pusher/pusher-websocket-swift/issues/109 for more information")
79+
print("""
80+
Your Pusher instance has probably become deallocated. \
81+
See https://github.com/pusher/pusher-websocket-swift/issues/109 \
82+
for more information
83+
""")
7684
return
7785
}
7886

@@ -487,7 +495,8 @@ import Starscream
487495

488496
if PusherChannelType.isPresenceChannel(name: channelName) {
489497
if let presChan = self.channels.find(name: channelName) as? PusherPresenceChannel {
490-
if let dataJSON = event.dataToJSONObject() as? [String: Any], let presenceData = dataJSON["presence"] as? [String: AnyObject],
498+
if let dataJSON = event.dataToJSONObject() as? [String: Any],
499+
let presenceData = dataJSON["presence"] as? [String: AnyObject],
491500
let presenceHash = presenceData["hash"] as? [String: AnyObject] {
492501
presChan.addExistingMembers(memberHash: presenceHash)
493502
}
@@ -524,7 +533,8 @@ import Starscream
524533
self.reconnectAttempts = 0
525534
self.reconnectTimer?.invalidate()
526535

527-
if options.activityTimeout == nil, let activityTimeoutFromServer = connectionData["activity_timeout"] as? TimeInterval {
536+
if options.activityTimeout == nil,
537+
let activityTimeoutFromServer = connectionData["activity_timeout"] as? TimeInterval {
528538
self.activityTimeoutInterval = activityTimeoutFromServer
529539
}
530540

@@ -550,7 +560,8 @@ import Starscream
550560
- parameter event: The event to be processed
551561
*/
552562
fileprivate func handleMemberAddedEvent(event: PusherEvent) {
553-
if let channelName = event.channelName, let chan = self.channels.find(name: channelName) as? PusherPresenceChannel {
563+
if let channelName = event.channelName,
564+
let chan = self.channels.find(name: channelName) as? PusherPresenceChannel {
554565
if let memberJSON = event.dataToJSONObject() as? [String: Any] {
555566
chan.addMember(memberJSON: memberJSON)
556567
} else {
@@ -565,7 +576,8 @@ import Starscream
565576
- parameter event: The event to be processed
566577
*/
567578
fileprivate func handleMemberRemovedEvent(event: PusherEvent) {
568-
if let channelName = event.channelName, let chan = self.channels.find(name: channelName) as? PusherPresenceChannel {
579+
if let channelName = event.channelName,
580+
let chan = self.channels.find(name: channelName) as? PusherPresenceChannel {
569581
if let memberJSON = event.dataToJSONObject() as? [String: Any] {
570582
chan.removeMember(memberJSON: memberJSON)
571583
} else {
@@ -607,7 +619,10 @@ import Starscream
607619
if let message = error.message {
608620
print(message)
609621
}
610-
self.delegate?.failedToSubscribeToChannel?(name: channelName, response: error.response, data: error.data, error: error.error)
622+
self.delegate?.failedToSubscribeToChannel?(name: channelName,
623+
response: error.response,
624+
data: error.data,
625+
error: error.error)
611626
}
612627
}
613628

@@ -682,7 +697,8 @@ import Starscream
682697
}
683698
}
684699

685-
fileprivate func requestPusherAuthFromAuthMethod(channel: PusherChannel, completionHandler:@escaping (PusherAuth?, PusherAuthError?) -> Void) -> Bool {
700+
fileprivate func requestPusherAuthFromAuthMethod(channel: PusherChannel,
701+
completionHandler: @escaping (PusherAuth?, PusherAuthError?) -> Void) -> Bool {
686702
guard let socketId = self.socketId else {
687703
let message = "socketId value not found. You may not be connected."
688704
completionHandler(nil, PusherAuthError(kind: .notConnected, message: message))
@@ -692,7 +708,9 @@ import Starscream
692708
switch self.options.authMethod {
693709
case .noMethod:
694710
let errorMessage = "Authentication method required for private / presence channels but none provided."
695-
let error = NSError(domain: "com.pusher.PusherSwift", code: 0, userInfo: [NSLocalizedFailureReasonErrorKey: errorMessage])
711+
let error = NSError(domain: "com.pusher.PusherSwift",
712+
code: 0,
713+
userInfo: [NSLocalizedFailureReasonErrorKey: errorMessage])
696714
completionHandler(nil, PusherAuthError(kind: .noMethod, message: errorMessage, error: error))
697715
return false
698716
case .endpoint(authEndpoint: let authEndpoint):
@@ -705,8 +723,12 @@ import Starscream
705723
return true
706724
} else {
707725
let errorMessage = "Authentication request could not be built"
708-
let error = NSError(domain: "com.pusher.PusherSwift", code: 0, userInfo: [NSLocalizedFailureReasonErrorKey: errorMessage])
709-
completionHandler(nil, PusherAuthError(kind: .couldNotBuildRequest, message: errorMessage, error: error))
726+
let error = NSError(domain: "com.pusher.PusherSwift",
727+
code: 0,
728+
userInfo: [NSLocalizedFailureReasonErrorKey: errorMessage])
729+
completionHandler(nil, PusherAuthError(kind: .couldNotBuildRequest,
730+
message: errorMessage,
731+
error: error))
710732
return false
711733
}
712734
case .authorizer(authorizer: let authorizer):
@@ -807,36 +829,53 @@ import Starscream
807829
- parameter request: The request to send
808830
- parameter channel: The PusherChannel to authenticate subsciption for
809831
*/
810-
fileprivate func sendAuthorisationRequest(request: URLRequest, channel: PusherChannel, completionHandler: @escaping (PusherAuth?, PusherAuthError?) -> Void) {
832+
fileprivate func sendAuthorisationRequest(request: URLRequest,
833+
channel: PusherChannel,
834+
completionHandler: @escaping (PusherAuth?, PusherAuthError?) -> Void) {
811835
let task = URLSession.dataTask(with: request, completionHandler: { data, response, sessionError in
812836
if let error = sessionError {
813837
let message = "Error authorizing channel [\(channel.name)]: \(error)"
814-
completionHandler(nil, PusherAuthError(kind: .requestFailure, message: message, response: response, error: error as NSError?))
838+
completionHandler(nil, PusherAuthError(kind: .requestFailure,
839+
message: message,
840+
response: response,
841+
error: error as NSError?))
815842
return
816843
}
817844

818845
guard let data = data else {
819846
let message = "Error authorizing channel [\(channel.name)]"
820-
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse, message: message, response: response))
847+
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse,
848+
message: message,
849+
response: response))
821850
return
822851
}
823852

824-
guard let httpResponse = response as? HTTPURLResponse, (httpResponse.statusCode == 200 || httpResponse.statusCode == 201) else {
853+
guard let httpResponse = response as? HTTPURLResponse,
854+
(httpResponse.statusCode == 200 || httpResponse.statusCode == 201) else {
825855
let dataString = String(data: data, encoding: String.Encoding.utf8)
826856
let message = "Error authorizing channel [\(channel.name)]: \(String(describing: dataString))"
827-
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse, message: message, response: response, data: dataString))
857+
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse,
858+
message: message,
859+
response: response,
860+
data: dataString))
828861
return
829862
}
830863

831-
guard let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []), let json = jsonObject as? [String: AnyObject] else {
864+
guard let jsonObject = try? JSONSerialization.jsonObject(with: data,
865+
options: []),
866+
let json = jsonObject as? [String: AnyObject] else {
832867
let message = "Error authorizing channel [\(channel.name)]: Could not parse response from auth endpoint"
833-
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse, message: message, response: httpResponse))
868+
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse,
869+
message: message,
870+
response: httpResponse))
834871
return
835872
}
836873

837874
guard let auth = json["auth"] as? String else {
838875
let message = "Error authorizing channel [\(channel.name)]: No auth field in response"
839-
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse, message: message, response: httpResponse))
876+
completionHandler(nil, PusherAuthError(kind: .invalidAuthResponse,
877+
message: message,
878+
response: httpResponse))
840879
return
841880
}
842881

@@ -919,7 +958,9 @@ extension PusherConnection: PusherEventQueueDelegate {
919958
}
920959
}
921960

922-
func eventQueue(_ eventQueue: PusherEventQueue, didFailToDecryptEventWithPayload payload: PusherEventPayload, forChannelName channelName: String) {
961+
func eventQueue(_ eventQueue: PusherEventQueue,
962+
didFailToDecryptEventWithPayload payload: PusherEventPayload,
963+
forChannelName channelName: String) {
923964
DispatchQueue.main.async {
924965
if let eventName = payload["event"] as? String {
925966
let data = payload["data"] as? String
@@ -929,7 +970,9 @@ extension PusherConnection: PusherEventQueueDelegate {
929970
}
930971
}
931972

932-
func eventQueue(_ eventQueue: PusherEventQueue, didReceiveEvent event: PusherEvent, forChannelName channelName: String?) {
973+
func eventQueue(_ eventQueue: PusherEventQueue,
974+
didReceiveEvent event: PusherEvent,
975+
forChannelName channelName: String?) {
933976
DispatchQueue.main.async {
934977
self.handleEvent(event: event)
935978
}

Sources/PusherCrypto.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ struct PusherCrypto {
2020
_ = digest.withUnsafeMutableBytes { (digestBytes: UnsafeMutableRawBufferPointer) in
2121
_ = secretData.withUnsafeBytes { (secretBytes: UnsafeRawBufferPointer) in
2222
_ = messageData.withUnsafeBytes { (messageBytes: UnsafeRawBufferPointer) in
23-
CCHmac(algorithm, secretBytes.baseAddress, secretData.count, messageBytes.baseAddress, messageData.count, digestBytes.baseAddress)
23+
CCHmac(algorithm,
24+
secretBytes.baseAddress,
25+
secretData.count,
26+
messageBytes.baseAddress,
27+
messageData.count,
28+
digestBytes.baseAddress)
2429
}
2530
}
2631
}

Sources/PusherError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Foundation
33
@objcMembers
44
open class PusherError: NSObject {
55

6-
// Code is optional, message is not: https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#-pusher-error-channels-client-
6+
/// Code is optional, message is not:
7+
/// https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#-pusher-error-channels-client-
78
/// The error code.
89
public let code: Int?
910
/// The error message.

Sources/PusherEvent.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ open class PusherEvent: NSObject, NSCopying {
66
/// The JSON object received from the websocket
77
@nonobjc internal let raw: [String: Any]
88

9-
// According to Channels protocol, there is always an event https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#events
9+
/// According to Channels protocol, there is always an event
10+
/// https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#events
1011
/// The name of the event.
1112
public let eventName: String
1213

13-
/// The name of the channel that the event was triggered on. Not present in events without an associated channel, e.g. "pusher:error" events relating to the connection.
14+
/// The name of the channel that the event was triggered on.
15+
/// Not present in events without an associated channel, e.g. "pusher:error" events relating to the connection.
1416
public let channelName: String?
1517

1618
/// The data that was passed when the event was triggered.
@@ -19,7 +21,11 @@ open class PusherEvent: NSObject, NSCopying {
1921
/// The ID of the user who triggered the event. Only present in client event on presence channels.
2022
public let userId: String?
2123

22-
@nonobjc internal init(eventName: String, channelName: String?, data: String?, userId: String?, raw: [String: Any]) {
24+
@nonobjc internal init(eventName: String,
25+
channelName: String?,
26+
data: String?,
27+
userId: String?,
28+
raw: [String: Any]) {
2329
self.eventName = eventName
2430
self.channelName = channelName
2531
self.data = data
@@ -65,11 +71,19 @@ open class PusherEvent: NSObject, NSCopying {
6571
@nonobjc internal func copy(withEventName eventName: String) -> PusherEvent {
6672
var jsonObject = self.raw
6773
jsonObject["event"] = eventName
68-
return PusherEvent(eventName: eventName, channelName: self.channelName, data: self.data, userId: self.userId, raw: jsonObject)
74+
return PusherEvent(eventName: eventName,
75+
channelName: self.channelName,
76+
data: self.data,
77+
userId: self.userId,
78+
raw: jsonObject)
6979
}
7080

7181
public func copy(with zone: NSZone? = nil) -> Any {
72-
return PusherEvent(eventName: self.eventName, channelName: self.channelName, data: self.data, userId: self.userId, raw: self.raw)
82+
return PusherEvent(eventName: self.eventName,
83+
channelName: self.channelName,
84+
data: self.data,
85+
userId: self.userId,
86+
raw: self.raw)
7387
}
7488

7589
}

Sources/PusherEventFactory.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@ struct PusherConcreteEventFactory: PusherEventFactory {
1212

1313
// MARK: - Event factory
1414

15-
func makeEvent(fromJSON json: PusherEventPayload, withDecryptionKey decryptionKey: String? = nil) throws -> PusherEvent {
15+
func makeEvent(fromJSON json: PusherEventPayload,
16+
withDecryptionKey decryptionKey: String? = nil) throws -> PusherEvent {
1617
guard let eventName = json["event"] as? String else {
1718
throw PusherEventError.invalidFormat
1819
}
1920

2021
let channelName = json["channel"] as? String
21-
let data = try self.data(fromJSON: json, eventName: eventName, channelName: channelName, decryptionKey: decryptionKey)
22+
let data = try self.data(fromJSON: json,
23+
eventName: eventName,
24+
channelName: channelName,
25+
decryptionKey: decryptionKey)
2226
let userId = json["user_id"] as? String
2327

2428
return PusherEvent(eventName: eventName, channelName: channelName, data: data, userId: userId, raw: json)
2529
}
2630

2731
// MARK: - Private methods
2832

29-
private func data(fromJSON json: PusherEventPayload, eventName: String, channelName: String?, decryptionKey: String?) throws -> String? {
33+
private func data(fromJSON json: PusherEventPayload,
34+
eventName: String,
35+
channelName: String?,
36+
decryptionKey: String?) throws -> String? {
3037
let data = json["data"] as? String
3138

3239
if PusherEncryptionHelpers.shouldDecryptMessage(eventName: eventName, channelName: channelName) {

0 commit comments

Comments
 (0)