convert to guard statements for readability

pull/1/head
Michael Kirk 7 years ago committed by Matthew Chen
parent ea76ea9492
commit 5d9e03ba40

@ -324,18 +324,24 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN
// Order matters; better results should appear first so prefer // Order matters; better results should appear first so prefer
// matches with the same country code as this client's phone number. // matches with the same country code as this client's phone number.
OWSAssertDebug(clientPhoneNumber.length > 0); if (clientPhoneNumber.length == 0) {
if (clientPhoneNumber.length > 0) { OWSFailDebug(@"clientPhoneNumber had unexpected length");
return result;
}
// Note that NBPhoneNumber uses "country code" to refer to what we call a // Note that NBPhoneNumber uses "country code" to refer to what we call a
// "calling code" (i.e. 44 in +44123123). Within SSK we use "country code" // "calling code" (i.e. 44 in +44123123). Within SSK we use "country code"
// (and sometimes "region code") to refer to a country's ISO 2-letter code // (and sometimes "region code") to refer to a country's ISO 2-letter code
// (ISO 3166-1 alpha-2). // (ISO 3166-1 alpha-2).
NSNumber *callingCodeForLocalNumber = [[PhoneNumber phoneNumberFromE164:clientPhoneNumber] getCountryCode]; NSNumber *callingCodeForLocalNumber = [[PhoneNumber phoneNumberFromE164:clientPhoneNumber] getCountryCode];
if (callingCodeForLocalNumber != nil) { if (callingCodeForLocalNumber == nil) {
OWSFailDebug(@"callingCodeForLocalNumber was unexpectedly nil");
return result;
}
NSString *callingCodePrefix = [NSString stringWithFormat:@"+%@", callingCodeForLocalNumber]; NSString *callingCodePrefix = [NSString stringWithFormat:@"+%@", callingCodeForLocalNumber];
tryParsingWithCountryCode( tryParsingWithCountryCode([callingCodePrefix stringByAppendingString:sanitizedString], [self defaultCountryCode]);
[callingCodePrefix stringByAppendingString:sanitizedString], [self defaultCountryCode]);
// Try to determine what the country code is for the local phone number // Try to determine what the country code is for the local phone number
// and also try parsing the phone number using that country code if it // and also try parsing the phone number using that country code if it
@ -347,10 +353,7 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN
NSString *localCountryCode = NSString *localCountryCode =
[PhoneNumberUtil.sharedThreadLocal probableCountryCodeForCallingCode:callingCodePrefix]; [PhoneNumberUtil.sharedThreadLocal probableCountryCodeForCallingCode:callingCodePrefix];
if (localCountryCode && ![localCountryCode isEqualToString:[self defaultCountryCode]]) { if (localCountryCode && ![localCountryCode isEqualToString:[self defaultCountryCode]]) {
tryParsingWithCountryCode( tryParsingWithCountryCode([callingCodePrefix stringByAppendingString:sanitizedString], localCountryCode);
[callingCodePrefix stringByAppendingString:sanitizedString], localCountryCode);
}
}
} }
return result; return result;

Loading…
Cancel
Save