bikeindex/bike_index

View on GitHub
app/models/b_param.rb

Summary

Maintainability
C
1 day
Test Coverage
B
84%

Class BParam has 74 methods (exceeds 40 allowed). Consider refactoring.
Open

class BParam < ApplicationRecord
  mount_uploader :image, ImageUploader
  store_in_background :image, CarrierWaveStoreWorker

  # serialize :params
Severity: Major
Found in app/models/b_param.rb - About 7 hrs to fix

    Method find_or_new_from_token has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

      def self.find_or_new_from_token(toke = nil, user_id: nil, organization_id: nil, bike_sticker: nil)
        b = where(creator_id: user_id, id_token: toke).first if toke.present? && user_id.present?
        b ||= with_organization_or_no_creator(toke)
        b ||= BParam.new(creator_id: user_id, params: {revised_new: true}.as_json)
        b.creator_id ||= user_id
    Severity: Minor
    Found in app/models/b_param.rb - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method v2_params has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

      def self.v2_params(hash)
        h = hash["bike"].present? ? hash : {"bike" => hash.with_indifferent_access}
        # Only assign if the key hasn't been assigned - since it's boolean, can't use conditional assignment
        h["bike"]["serial_number"] = h["bike"].delete "serial" if h["bike"].key?("serial")
        h["bike"]["send_email"] = !(h["bike"].delete "no_notify") unless h["bike"].key?("send_email")
    Severity: Minor
    Found in app/models/b_param.rb - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method set_paint_key has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
    Open

      def set_paint_key(paint_entry)
        return nil unless paint_entry.present?
    
        paint = Paint.friendly_find(paint_entry)
    
    
    Severity: Minor
    Found in app/models/b_param.rb - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    There are no issues that match your filters.

    Category
    Status