Two methods having the same implementation are suspicious. It might be that something else was intended. Or the duplication is intentional, which
becomes a maintenance burden.
class Circle
def initialize(radius)
@radius = radius
end
def width=(size)
@radius = size / 2
update_shape()
end
def height=(size) # Noncompliant: duplicates width
@radius = size / 2
update_shape()
end
def updateShape()
...
end
end
If the identical logic is intentional, the code should be refactored to avoid duplication. For example, by having both methods call the same method
or by having one implementation invoke the other.
class Circle
def initialize(radius)
@radius = radius
end
def width=(width)
self.diameter = width
end
def height=(height)
self.diameter = height
end
def diameter=(diameter) # Implementation is shared
@radius = diameter / 2
update_shape()
end
def update_shape()
# ...
end
end
Exceptions
Methods with fewer than 2 statements are ignored.