我很困惑RuboCop在抱怨什么。ABC大小太高,即使没有分支,分配或条件
“为拉伸分配分支条件大小过高[一十五分之二十九]。”
为下述方法:
class Ball
attr_reader :color
attr_reader :center
attr_reader :radius
attr_reader :dir
attr_reader :x, :y
attr_reader :w, :h
attr_accessor :worldWidth
attr_accessor :worldHeight
...
# Draw the ball into this device context
def draw(dc)
dc.setForeground(color)
dc.fillArc(x, y, w, h, 0, 64 * 90)
dc.fillArc(x, y, w, h, 64 * 90, 64 * 180)
dc.fillArc(x, y, w, h, 64 * 180, 64 * 270)
dc.fillArc(x, y, w, h, 64 * 270, 64 * 360)
end
...
因为有没有分配,分支,在这里也没有条件!
我错过了什么?无论如何,这个功能有什么不好?要改变它似乎很愚蠢,我不清楚它会带来什么“好处”。请澄清!
我不完全了解ABC(作业/分支/条件)的工作原理,但您可以从[wikipedia](https://en.wikipedia.org/wiki/ABC_score)页面看到函数调用通常会被处理作为分支。 [这里](https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/metrics/abc_size.rb)是决定这个分数的rubocop来源,[here](https:// github.com/bbatsov/rubocop/blob/master/config/default.yml)是rubocop默认值(默认的最大ABC分数是15)。 –