我很困惑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)。 –