Class: Hashira::Complexity::MethodFinding

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/complexity/method_finding.rb

Constant Summary collapse

ADVICE =
{
  "if" => "flatten the branching — guard clauses, early returns, or polymorphism.",
  "elsif" => "replace the elsif ladder with a lookup or polymorphic dispatch.",
  "else" => "flatten the branching — guard clauses, early returns, or polymorphism.",
  "case" => "a case this size often wants polymorphism or a dispatch table.",
  "boolean" => "name the compound condition in a predicate method.",
  "rescue" => "narrow the rescue, or lift error handling to the caller.",
  "while" => "extract the loop body into its own method.",
  "until" => "extract the loop body into its own method.",
  "for" => "extract the loop body into its own method.",
  "unless" => "invert to a guard clause or a named predicate.",
  "ternary" => "extract the nested ternary into a named method."
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(score) ⇒ MethodFinding

Returns a new instance of MethodFinding.



20
21
22
# File 'lib/hashira/complexity/method_finding.rb', line 20

def initialize(score)
  @score = score
end

Instance Method Details

#to_findingObject



24
25
26
27
# File 'lib/hashira/complexity/method_finding.rb', line 24

def to_finding
  Analysis::Finding.new(kind: "complexity", package: @score.subject, cycle: nil,
                        message:, evidence:)
end