Skip to content

Commit

Permalink
A few more static analysis fixes
Browse files Browse the repository at this point in the history
Xcode static analyser seems to be somehow broken. 💥
  • Loading branch information
username0x0a committed Jan 24, 2020
1 parent f872088 commit f1f4fa1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
14 changes: 7 additions & 7 deletions TravelKit/TKAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,11 @@ - (instancetype)initAsPlacesRequestForQuery:(TKPlacesQuery *)query
queryDict[@"parents"] = [query.parentIDs componentsJoinedByString:operator];
}

if (query.minimumRating || query.maximumRating)
if (query.minimumRating != nil || query.maximumRating != nil)
{
NSString *minString = (query.minimumRating) ?
NSString *minString = (query.minimumRating != nil) ?
[NSString stringWithFormat:@"%.5f", query.minimumRating.floatValue] : @"";
NSString *maxString = (query.maximumRating) ?
NSString *maxString = (query.maximumRating != nil) ?
[NSString stringWithFormat:@"%.5f", query.maximumRating.floatValue] : @"";
queryDict[@"rating"] = [NSString stringWithFormat:@"%@:%@",
minString, maxString];
Expand Down Expand Up @@ -1023,7 +1023,7 @@ - (instancetype)initAsViatorToursRequestForQuery:(TKToursViatorQuery *)query
queryDict[@"sort_direction"] = direction;
}

if (query.pageNumber)
if (query.pageNumber != nil)
{
NSUInteger page = query.pageNumber.unsignedIntegerValue;
if (page > 1) queryDict[@"page"] = [query.pageNumber stringValue];
Expand Down Expand Up @@ -1091,13 +1091,13 @@ - (instancetype)initAsGYGToursRequestForQuery:(TKToursGYGQuery *)query
if (query.pageNumber.unsignedIntegerValue > 1)
queryDict[@"page"] = [query.pageNumber stringValue];

if (query.count)
if (query.count != nil)
queryDict[@"count"] = [query.count stringValue];

if (query.searchTerm)
queryDict[@"query"] = query.searchTerm;

if (query.minimalDuration || query.maximalDuration)
if (query.minimalDuration != nil || query.maximalDuration != nil)
queryDict[@"duration"] = [NSString stringWithFormat:@"%@:%@",
query.minimalDuration ?: @"", query.maximalDuration ?: @""];

Expand Down Expand Up @@ -1317,7 +1317,7 @@ - (instancetype)initAsExchangeRatesRequestWithSuccess:(void (^)(NSDictionary<NSS
NSString *code = [e[@"code"] parsedString];
NSNumber *rate = [e[@"rate"] parsedNumber];

if (code && rate)
if (code != nil && rate != nil)
exchangeRates[code] = rate;
}

Expand Down
8 changes: 4 additions & 4 deletions TravelKit/TKDirection.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ - (instancetype)initFromDictionary:(NSDictionary *)dictionary
{
NSNumber *lat = [dictionary[@"origin"][@"lat"] parsedNumber];
NSNumber *lng = [dictionary[@"origin"][@"lng"] parsedNumber];
if (lat && lng) _sourceLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];
if (lat != nil && lng != nil) _sourceLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];
lat = [dictionary[@"destination"][@"lat"] parsedNumber];
lng = [dictionary[@"destination"][@"lng"] parsedNumber];
if (lat && lng) _destinationLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];
if (lat != nil && lng != nil) _destinationLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];

if (!_sourceLocation || !_destinationLocation)
return nil;
Expand Down Expand Up @@ -212,12 +212,12 @@ - (instancetype)initFromDictionary:(NSDictionary *)dictionary
_originName = [dictionary[@"origin"][@"name"] parsedString];
NSNumber *lat = [dictionary[@"origin"][@"location"][@"lat"] parsedNumber];
NSNumber *lng = [dictionary[@"origin"][@"location"][@"lng"] parsedNumber];
if (lat && lng) _originLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];
if (lat != nil && lng != nil) _originLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];

_destinationName = [dictionary[@"destination"][@"name"] parsedString];
lat = [dictionary[@"destination"][@"location"][@"lat"] parsedNumber];
lng = [dictionary[@"destination"][@"location"][@"lng"] parsedNumber];
if (lat && lng) _destinationLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];
if (lat != nil && lng != nil) _destinationLocation = [[CLLocation alloc] initWithLatitude:lat.doubleValue longitude:lng.doubleValue];

_headsign = [dictionary[@"display_info"][@"headsign"] parsedString];
_shortName = [dictionary[@"display_info"][@"name_short"] parsedString];
Expand Down
6 changes: 3 additions & 3 deletions TravelKit/TKPlace.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (instancetype)initFromResponse:(NSDictionary *)dictionary
NSNumber *lat = [location[@"lat"] parsedNumber];
NSNumber *lng = [location[@"lng"] parsedNumber];

if (lat && lng) _location = [[CLLocation alloc]
if (lat != nil && lng != nil) _location = [[CLLocation alloc]
initWithLatitude:lat.doubleValue longitude:lng.doubleValue];

if (!_ID || !_name || !_location) return nil;
Expand All @@ -131,11 +131,11 @@ - (instancetype)initFromResponse:(NSDictionary *)dictionary
{
lat = [dictionary[@"south"] parsedNumber];
lng = [dictionary[@"west"] parsedNumber];
CLLocation *southWest = (lat && lng) ? [[CLLocation alloc]
CLLocation *southWest = (lat != nil && lng != nil) ? [[CLLocation alloc]
initWithLatitude:lat.doubleValue longitude:lng.doubleValue] : nil;
lat = [dictionary[@"north"] parsedNumber];
lng = [dictionary[@"east"] parsedNumber];
CLLocation *northEast = (lat && lng) ? [[CLLocation alloc]
CLLocation *northEast = (lat != nil && lng != nil) ? [[CLLocation alloc]
initWithLatitude:lat.doubleValue longitude:lng.doubleValue] : nil;
if (southWest && northEast)
_boundingBox = [[TKMapRegion alloc]
Expand Down
2 changes: 1 addition & 1 deletion TravelKit/TKReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (instancetype)initFromResponse:(NSDictionary *)response

#pragma clang diagnostic pop

if (!ID || !_title || !_type || !_onlineURL)
if (ID == nil || !_title || !_type || !_onlineURL)
return nil;

_supplier = [response[@"supplier"] parsedString];
Expand Down
8 changes: 4 additions & 4 deletions TravelKit/TKSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ - (instancetype)initFromDictionary:(NSDictionary *)dictionary
NSNumber *refresh = [dictionary[@"refreshDate"] parsedNumber];
NSNumber *expiration = [dictionary[@"expirationDate"] parsedNumber];

if (refresh) _refreshDate = [NSDate dateWithTimeIntervalSince1970:floor(refresh.doubleValue)];
if (expiration) _expirationDate = [NSDate dateWithTimeIntervalSince1970:floor(expiration.doubleValue)];
if (refresh != nil) _refreshDate = [NSDate dateWithTimeIntervalSince1970:floor(refresh.doubleValue)];
if (expiration != nil) _expirationDate = [NSDate dateWithTimeIntervalSince1970:floor(expiration.doubleValue)];
else {
expiration = [dictionary[@"expires_in"] parsedNumber];
NSTimeInterval refreshInterval = floor(expiration.doubleValue * 0.8);
NSTimeInterval expiryInterval = floor(expiration.doubleValue);
if (expiration) _refreshDate = [[NSDate new] dateByAddingTimeInterval:refreshInterval];
if (expiration) _expirationDate = [[NSDate new] dateByAddingTimeInterval:expiryInterval];
if (expiration != nil) _refreshDate = [[NSDate new] dateByAddingTimeInterval:refreshInterval];
if (expiration != nil) _expirationDate = [[NSDate new] dateByAddingTimeInterval:expiryInterval];
}

if (!_accessToken || !_refreshToken || !_expirationDate)
Expand Down
14 changes: 9 additions & 5 deletions TravelKit/TKSynchronizationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,19 +506,23 @@ - (void)synchronizeChanges

- (void)resolveTripConflicts
{
if (!_tripConflicts.count) {
NSArray<TKTripConflict *> *conlicts = [_tripConflicts copy];

if (!conlicts.count) {
[self checkState];
return;
}

if (_events.tripConflictsHandler)
__auto_type handler = _events.tripConflictsHandler;

if (handler)
{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
_events.tripConflictsHandler(_tripConflicts, ^{
handler(conlicts, ^{

for (TKTripConflict *conf in _tripConflicts)
for (TKTripConflict *conf in conlicts)
{
TKTrip *localTrip = conf.localTrip;

Expand Down Expand Up @@ -555,7 +559,7 @@ - (void)resolveTripConflicts
}

else
for (TKTripConflict *conf in _tripConflicts.copy)
for (TKTripConflict *conf in conlicts)
[self processResponseWithTrip:conf.remoteTrip sentTripID:conf.localTrip.ID];

[self checkState];
Expand Down
2 changes: 1 addition & 1 deletion TravelKit/TKTour.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (instancetype)initFromResponse:(NSDictionary *)dictionary
_rating = [dictionary[@"rating"] parsedNumber];
_price = [dictionary[@"price"] parsedNumber];
_originalPrice = [dictionary[@"original_price"] parsedNumber];
if (_originalPrice.intValue == 0) _originalPrice = nil;
if (_originalPrice && _originalPrice.intValue == 0) _originalPrice = nil;
_reviewsCount = [dictionary[@"review_count"] parsedNumber];

_duration = [dictionary[@"duration"] parsedString];
Expand Down
2 changes: 1 addition & 1 deletion TravelKit/TKTrip.m
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ - (instancetype)initFromResponse:(NSDictionary *)dictionary
NSDictionary *tripDict = [dictionary[@"trip"] parsedDictionary];
if (tripDict) _trip = [[TKTrip alloc] initFromResponse:tripDict];

if (!_ID || !_trip) return nil;
if (_ID == nil || !_trip) return nil;

_duration = [dictionary[@"duration"] parsedNumber] ?:
@(_trip.days.count * 86400);
Expand Down

0 comments on commit f1f4fa1

Please sign in to comment.