versioneye/naturalsorter

View on GitHub
lib/versioncmp.rb

Summary

Maintainability
F
3 days
Test Coverage

Method compare_special_cases has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

  def self.compare_special_cases part1, part2
    result = Versioncmp.check_jquery_versioning(part1, part2)
    return result if !result.to_s.strip.empty?

    digit = part1 if part1.to_s.match(/\d/)
Severity: Minor
Found in lib/versioncmp.rb - About 5 hrs 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 compare has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def self.compare(a_val, b_val)

    a_empty = a_val.to_s.empty?
    b_empty = b_val.to_s.empty?

Severity: Minor
Found in lib/versioncmp.rb - About 3 hrs 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

Class Versioncmp has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class Versioncmp

  # 'Natural version order' comparison of two version strings
  #
  def self.compare(a_val, b_val)
Severity: Minor
Found in lib/versioncmp.rb - About 2 hrs to fix

    Method compare has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.compare(a_val, b_val)
    
        a_empty = a_val.to_s.empty?
        b_empty = b_val.to_s.empty?
    
    
    Severity: Minor
    Found in lib/versioncmp.rb - About 1 hr to fix

      Method compare_special_cases has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.compare_special_cases part1, part2
          result = Versioncmp.check_jquery_versioning(part1, part2)
          return result if !result.to_s.strip.empty?
      
          digit = part1 if part1.to_s.match(/\d/)
      Severity: Minor
      Found in lib/versioncmp.rb - About 1 hr to fix

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

          def self.check_the_slice ab, offsets
            ab[0] += ".0" if offsets[0] >= ab[0].length
            ab[1] += ".0" if offsets[0] >= ab[1].length
        
            part1 = Versioncmp.get_a_piece_of_the_cake offsets[0], ab[0]
        Severity: Minor
        Found in lib/versioncmp.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 get_a_piece_of_the_cake has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.get_a_piece_of_the_cake(offset, cake)
            for z in 0..100
              offsetz = offset + z
              break if offsetz > cake.length()
        
        
        Severity: Minor
        Found in lib/versioncmp.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 check_jquery_versioning has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.check_jquery_versioning(part1, part2)
            # --- START ---- special case for awesome jquery shitty verison numbers
            if ( part1.to_s.match(/^[0-9]+[a-zA-Z]+[0-9]+$/) != nil && part2.to_s.match(/^[0-9]+$/) != nil )
              part1_1 = part1.match(/^[0-9]+/)
              result = Versioncmp.compare_int(part1_1[0], part2)
        Severity: Minor
        Found in lib/versioncmp.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 -1 if b_val.length > a_val.length && b_val.to_s.match(/\A#{a_val}u\d/i)
        Severity: Major
        Found in lib/versioncmp.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

              return -1 if ( pm1 && pm2 && pm2[1].eql?(part1) && !VersionTagRecognizer.stable?(pm2[2]) )
          Severity: Major
          Found in lib/versioncmp.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                return -1 if ( part1.eql?("0") && part2.to_s.match(/^[1-9]+[-_a-zA-Z]+/) )
            Severity: Major
            Found in lib/versioncmp.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

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

                Avoid too many return statements within this method.
                Open

                    return -1 if a_val.length > b_val.length && a_val.to_s.match(/\A#{a_val}-SNAPSHOT/i)
                Severity: Major
                Found in lib/versioncmp.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                      return -1 if a_val.length > b_val.length && a_val.to_s.match(/\A#{a_val}-alpha.*/i)
                  Severity: Major
                  Found in lib/versioncmp.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                        return -1 if am && bm && am[1].eql?(bm[1])
                    Severity: Major
                    Found in lib/versioncmp.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                          return  1 if ( part2.eql?("0") && part1.to_s.match(/^[1-9]+[-_a-zA-Z]+/) )
                      Severity: Major
                      Found in lib/versioncmp.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                            return  1 if ( pm1 && pm2 && pm2[1].eql?(part1) &&  VersionTagRecognizer.stable?(pm2[2]) )
                        Severity: Major
                        Found in lib/versioncmp.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                              return 1 if try_to_i_bigger( pm1, pm2, part2 )
                          Severity: Major
                          Found in lib/versioncmp.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                return  1 if b_val.length > a_val.length && b_val.to_s.match(/\A#{a_val}-BETA.*/i)
                            Severity: Major
                            Found in lib/versioncmp.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                  return  1 if b_val.length > a_val.length && b_val.to_s.match(/\A#{a_val}-rc.*/i)
                              Severity: Major
                              Found in lib/versioncmp.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                    return -1 if ( part2.eql?("0") && part1.to_s.match(/^[a-zA-Z]+/) )
                                Severity: Major
                                Found in lib/versioncmp.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                      return  1 if am && bm && am[1].eql?(bm[1])
                                  Severity: Major
                                  Found in lib/versioncmp.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                        return  1 if ( part1.match(/\A[0-9]+\z/) && !part2.match(/\A[0-9]+\z/) )
                                    Severity: Major
                                    Found in lib/versioncmp.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                          return  1 if try_to_i_bigger( pm1, pm2, part2 )
                                      Severity: Major
                                      Found in lib/versioncmp.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                            return  1 if b_val.length > a_val.length && b_val.to_s.match(/\A#{a_val}-alpha.*/i)
                                        Severity: Major
                                        Found in lib/versioncmp.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

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

                                            Avoid too many return statements within this method.
                                            Open

                                                return -1 if a_val.length > b_val.length && a_val.to_s.match(/\A#{a_val}-rc.*/i)
                                            Severity: Major
                                            Found in lib/versioncmp.rb - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                  return  1 if a_val.length > b_val.length && a_val.to_s.match(/\A#{b_val}u\d/i)
                                              Severity: Major
                                              Found in lib/versioncmp.rb - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                    return  1 if ( part1.eql?("0") && part2.to_s.match(/^[a-zA-Z]+/) )
                                                Severity: Major
                                                Found in lib/versioncmp.rb - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                      return 1 if pm2 && pm1 && pm1[1].eql?(part2) && VersionTagRecognizer.stable?(pm1[2])
                                                  Severity: Major
                                                  Found in lib/versioncmp.rb - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                        return  1 if b_val.length > a_val.length && b_val.to_s.match(/\A#{a_val}-SNAPSHOT/i)
                                                    Severity: Major
                                                    Found in lib/versioncmp.rb - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

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

                                                        Avoid too many return statements within this method.
                                                        Open

                                                            return -1 if pm1 && pm2 && pm2[1].eql?(part1) && VersionTagRecognizer.stable?(pm2[2])
                                                        Severity: Major
                                                        Found in lib/versioncmp.rb - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                              return -1;
                                                          Severity: Major
                                                          Found in lib/versioncmp.rb - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                  return self.compare_special_cases part1, part2
                                                            Severity: Major
                                                            Found in lib/versioncmp.rb - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                  return -1 if a_val.length > b_val.length && a_val.to_s.match(/\A#{a_val}-BETA.*/i)
                                                              Severity: Major
                                                              Found in lib/versioncmp.rb - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                      return result if result == 1 || result == -1
                                                                Severity: Major
                                                                Found in lib/versioncmp.rb - About 30 mins to fix

                                                                  There are no issues that match your filters.

                                                                  Category
                                                                  Status