olbrich/ruby-units

View on GitHub

Showing 33 of 62 total issues

Method <=> has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def <=>(other)
      raise NoMethodError, "undefined method `<=>' for #{base_scalar.inspect}" unless base_scalar.respond_to?(:<=>)

      if other.nil?
        base_scalar <=> nil
Severity: Minor
Found in lib/ruby_units/unit.rb - About 1 hr 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 - has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def -(other)
      case other
      when Unit
        if zero?
          if other.zero?
Severity: Minor
Found in lib/ruby_units/unit.rb - About 1 hr to fix

    Method root has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def root(n)
          raise ArgumentError, "Cannot take the root of a temperature" if temperature?
          raise ArgumentError, "Exponent must an Integer" unless n.is_a?(Integer)
          raise ArgumentError, "0th root undefined" if n.zero?
          return self if n == 1
    Severity: Minor
    Found in lib/ruby_units/unit.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 == has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def ==(other)
          if other.respond_to?(:zero?) && other.zero?
            zero?
          elsif other.instance_of?(Unit)
            return false unless self =~ other
    Severity: Minor
    Found in lib/ruby_units/unit.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(name, definition = [])
          yield self if block_given?
          self.name     ||= name.gsub(/[<>]/, "")
          @aliases      ||= definition[0] || [name]
          @scalar       ||= definition[1]
    Severity: Minor
    Found in lib/ruby_units/definition.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 at has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def at(*args, **kwargs)
            case args.first
            when RubyUnits::Unit
              options = args.last.is_a?(Hash) ? args.pop : kwargs
              secondary_unit = args[2] || "microsecond"
    Severity: Minor
    Found in lib/ruby_units/time.rb - About 35 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 power has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def power(n)
          raise ArgumentError, "Cannot raise a temperature to a power" if temperature?
          raise ArgumentError, "Exponent must an Integer" unless n.is_a?(Integer)
          return inverse if n == -1
          return 1 if n.zero?
    Severity: Minor
    Found in lib/ruby_units/unit.rb - About 35 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 unit_signature_vector has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def unit_signature_vector
          return to_base.unit_signature_vector unless base?
    
          vector = ::Array.new(SIGNATURE_VECTOR.size, 0)
          # it's possible to have a kind that misses the array... kinds like :counting
    Severity: Minor
    Found in lib/ruby_units/unit.rb - About 35 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

    Avoid too many return statements within this method.
    Open

            return self if target.units == units
    Severity: Major
    Found in lib/ruby_units/unit.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return
      Severity: Major
      Found in lib/ruby_units/unit.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return
        Severity: Major
        Found in lib/ruby_units/unit.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return
          Severity: Major
          Found in lib/ruby_units/unit.rb - About 30 mins to fix

            Method use_definition has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.use_definition(definition)
                  @unit_match_regex = nil # invalidate the unit match regex
                  @temp_regex = nil # invalidate the temp regex
                  if definition.prefix?
                    prefix_values[definition.name] = definition.scalar
            Severity: Minor
            Found in lib/ruby_units/unit.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

            Severity
            Category
            Status
            Source
            Language