class RuboCop::Cop::Metrics::PerceivedComplexity
def complexity_score_for(node)
def complexity_score_for(node) case node.type when :case # If cond is nil, that means each when has an expression that # evaluates to true or false. It's just an alternative to # if/elsif/elsif... so the when nodes count. nb_branches = node.when_branches.length + (node.else_branch ? 1 : 0) if node.condition.nil? nb_branches else # Otherwise, the case node gets 0.8 complexity points and each # when gets 0.2. ((nb_branches * 0.2) + 0.8).round end when :if node.else? && !node.elsif? ? 2 : 1 else super end end