Updated

lib/rubycritic_small_badge / report.rb

A
66 lines of codes
8 methods
4.7 complexity/method
1 churn
37.78 complexity
0 duplications
# frozen_string_literal: true require 'repo_small_badge/image' require 'rubycritic_small_badge/configuration' module RubyCriticSmallBadge # Basic Badge Formater Class that creates the badges. class Report
  1. RubyCriticSmallBadge::Report assumes too much for instance variable '@image'
def initialize(analysed_modules) @config = RubyCriticSmallBadge.config @analysed_modules = analysed_modules end def generate_report mk_output_dir! score = @analysed_modules.score @image = RepoSmallBadge::Image.new(map_image_config(state(score))) badge('score', 'score', score) true end private def max_score 100.0 end def mk_output_dir!
  1. RubyCriticSmallBadge::Report has missing safe method 'mk_output_dir!'
FileUtils.mkdir_p(@config.output_path) end def badge(name, title, score) value_txt = score_text(score) @image.config_merge(map_image_config(state(score))) @image.badge(name, title, value_txt) end def score_text(score) "#{score}/#{max_score}" end def state(value) if @config.minimum_score&.positive?
  1. RubyCriticSmallBadge::Report#state calls '@config.minimum_score' 2 times Locations: 0 1
  2. RubyCriticSmallBadge::Report#state performs a nil-check
if value >= @config.minimum_score
  1. RubyCriticSmallBadge::Report#state calls '@config.minimum_score' 2 times Locations: 0 1
'good' else 'bad' end else 'unknown' end end def map_image_config(state)
  1. RubyCriticSmallBadge::Report#map_image_config has approx 6 statements
hash = {} @config.to_hash.map do |key, value| key = key
  1. RubyCriticSmallBadge::Report#map_image_config calls 'key; .to_s' 2 times Locations: 0 1
  2. RubyCriticSmallBadge::Report#map_image_config refers to 'key' more than self (maybe move it to another class?) Locations: 0 1
.to_s.sub(/^score_background_#{state}/, 'value_background') .to_sym key = key.to_s.sub(/^score_/, 'value_').to_sym
  1. RubyCriticSmallBadge::Report#map_image_config calls 'key; .to_s' 2 times Locations: 0 1
  2. RubyCriticSmallBadge::Report#map_image_config refers to 'key' more than self (maybe move it to another class?) Locations: 0 1
hash[key] = value end hash end end end