Greetings Sonar community.
We are running an objective C scan on code and this code below gets flagged with a “code smell” that the addObject is identical to the removeObject.
" Update this method so that its implementation is not identical to addObject."
-(void)addObject:(UIViCo*)vc
{
if (vc == nil)
return;
@synchronized (self) {
[pointerArray addPointer:(__bridge void* _Nullable)(vc)];
}
}
-(void)removeObject:(UIViCo*)vc {
Update this method so that its implementation is not identical to addObject.
if (vc == nil)
return;
@synchronized (self) {
for (NSInteger i = (NSInteger)pointerArray.count - 1; i >= 0; i--) {
if ([pointerArray pointerAtIndex:(NSUInteger)i] == (__bridge void* _Nullable)(vc)) {
[pointerArray removePointerAtIndex:(NSUInteger)i];
}
As you can see the removeObject is significantly different to the addObject. The example from “why is this an issue” shows 2 identical functions and would then I believe require us to change the variable vc to say vb in the second function. IMHO this makes readability worse.
Could someone explain this code smell better?
- which versions are you using
9.9.2 - how is SonarQube deployed: zip, Docker, Helm
Server install on vm - what are you trying to achieve
Compliant scan - what have you tried so far to achieve this
Normal product configuration.