olbrich/ruby-units

View on GitHub

Showing 62 of 62 total issues

Consider simplifying this complex logical expression.
Open

      if (other.is_a?(Unit) && other.temperature?) || (other.is_a?(String) && other =~ self.class.temp_regex)
        raise ArgumentError, "Receiver is not a temperature unit" unless degree?

        start_unit = units
        # @type [String]
Severity: Critical
Found in lib/ruby_units/unit.rb - About 1 hr to fix

    Method / has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def /(other)
          case other
          when Unit
            raise ZeroDivisionError if other.zero?
            raise ArgumentError, "Cannot divide with temperatures" if [other, self].any?(&:temperature?)
    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

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

          if (match = unit_string.match(FEET_INCH_REGEX))
            feet = Integer(match[:feet])
            inches = match[:inches]
            result = if feet.negative?
                       self.class.new("#{feet} ft") - self.class.new("#{inches} inches")
    Severity: Major
    Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
    lib/ruby_units/unit.rb on lines 1705..1715
    lib/ruby_units/unit.rb on lines 1718..1728

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

          if (match = unit_string.match(LBS_OZ_REGEX))
            pounds = Integer(match[:pounds])
            oz = match[:oz]
            result = if pounds.negative?
                       self.class.new("#{pounds} lbs") - self.class.new("#{oz} oz")
    Severity: Major
    Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
    lib/ruby_units/unit.rb on lines 1692..1702
    lib/ruby_units/unit.rb on lines 1718..1728

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

          if (match = unit_string.match(STONE_LB_REGEX))
            stone = Integer(match[:stone])
            pounds = match[:pounds]
            result = if stone.negative?
                       self.class.new("#{stone} stone") - self.class.new("#{pounds} lbs")
    Severity: Major
    Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
    lib/ruby_units/unit.rb on lines 1692..1702
    lib/ruby_units/unit.rb on lines 1705..1715

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

          when :stone
            stone, pounds = convert_to("lbs").scalar.abs.divmod(14)
            improper, frac = pounds.divmod(1)
            frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
            out = "#{negative? ? '-' : nil}#{stone}#{separator}stone #{improper}#{frac}#{separator}lbs"
    Severity: Major
    Found in lib/ruby_units/unit.rb and 1 other location - About 1 hr to fix
    lib/ruby_units/unit.rb on lines 686..690

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

          when :lbs
            pounds, ounces = convert_to("oz").scalar.abs.divmod(16)
            improper, frac = ounces.divmod(1)
            frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
            out  = "#{negative? ? '-' : nil}#{pounds}#{separator}lbs #{improper}#{frac}#{separator}oz"
    Severity: Major
    Found in lib/ruby_units/unit.rb and 1 other location - About 1 hr to fix
    lib/ruby_units/unit.rb on lines 691..695

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            @denominator = @denominator.map do |item|
              self.class.prefix_map[item[0]] ? [self.class.prefix_map[item[0]], self.class.unit_map[item[1]]] : [self.class.unit_map[item[1]]]
            end.flatten.compact.delete_if(&:empty?)
      Severity: Minor
      Found in lib/ruby_units/unit.rb and 1 other location - About 45 mins to fix
      lib/ruby_units/unit.rb on lines 1774..1776

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 41.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            @numerator = @numerator.map do |item|
              self.class.prefix_map[item[0]] ? [self.class.prefix_map[item[0]], self.class.unit_map[item[1]]] : [self.class.unit_map[item[1]]]
            end.flatten.compact.delete_if(&:empty?)
      Severity: Minor
      Found in lib/ruby_units/unit.rb and 1 other location - About 45 mins to fix
      lib/ruby_units/unit.rb on lines 1778..1780

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 41.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            unless den == UNITY_ARRAY
              definitions = den.map { self.class.definition(_1) }
              definitions.reject!(&:prefix?) unless with_prefix
              definitions = definitions.chunk_while { |definition, _| definition.prefix? }.to_a
              output_denominator = definitions.map { _1.map(&:display_name).join }
      Severity: Minor
      Found in lib/ruby_units/unit.rb and 1 other location - About 35 mins to fix
      lib/ruby_units/unit.rb on lines 1282..1286

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            unless num == UNITY_ARRAY
              definitions = num.map { self.class.definition(_1) }
              definitions.reject!(&:prefix?) unless with_prefix
              definitions = definitions.chunk_while { |definition, _| definition.prefix? }.to_a
              output_numerator = definitions.map { _1.map(&:display_name).join }
      Severity: Minor
      Found in lib/ruby_units/unit.rb and 1 other location - About 35 mins to fix
      lib/ruby_units/unit.rb on lines 1289..1293

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      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
        Severity
        Category
        Status
        Source
        Language