troessner/reek

View on GitHub
samples/smelly_source/optparse.rb

Summary

Maintainability
F
1 wk
Test Coverage

File optparse.rb has 869 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class OptionParser
  # :stopdoc:
  RCSID = %w$Id: optparse.rb 11798 2007-02-20 06:53:16Z knu $[1..-1].each {|s| s.freeze}.freeze
  Version = (RCSID[1].split('.').collect {|s| s.to_i}.extend(Comparable).freeze if RCSID[1])
  LastModified = (Time.gm(*RCSID[2, 2].join('-').scan(/\d+/).collect {|s| s.to_i}) if RCSID[2])
Severity: Major
Found in samples/smelly_source/optparse.rb - About 2 days to fix

    Method make_switch has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
    Open

      def make_switch(opts, block = nil)
        short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
        ldesc, sdesc, desc, arg = [], [], []
        default_style = Switch::NoArgument
        default_pattern = nil
    Severity: Minor
    Found in samples/smelly_source/optparse.rb - About 1 day 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 parse_in_order has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring.
    Open

      def parse_in_order(argv = default_argv, setter = nil, &nonopt)  # :nodoc:
        opt, arg, sw, val, rest = nil
        nonopt ||= proc {|arg| throw :terminate, arg}
        argv.unshift(arg) if arg = catch(:terminate) {
          while arg = argv.shift
    Severity: Minor
    Found in samples/smelly_source/optparse.rb - About 1 day 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 OptionParser has 59 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class OptionParser
      # :stopdoc:
      RCSID = %w$Id: optparse.rb 11798 2007-02-20 06:53:16Z knu $[1..-1].each {|s| s.freeze}.freeze
      Version = (RCSID[1].split('.').collect {|s| s.to_i}.extend(Comparable).freeze if RCSID[1])
      LastModified = (Time.gm(*RCSID[2, 2].join('-').scan(/\d+/).collect {|s| s.to_i}) if RCSID[2])
    Severity: Major
    Found in samples/smelly_source/optparse.rb - About 1 day to fix

      Method complete has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def complete(key, icase = false, pat = nil)
            pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
                               icase)
            canon, sw, k, v, cn = nil
            candidates = []
      Severity: Minor
      Found in samples/smelly_source/optparse.rb - About 4 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 make_switch has 109 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def make_switch(opts, block = nil)
          short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
          ldesc, sdesc, desc, arg = [], [], []
          default_style = Switch::NoArgument
          default_pattern = nil
      Severity: Major
      Found in samples/smelly_source/optparse.rb - About 4 hrs to fix

        Method summarize has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
              sopts, lopts, s = [], [], nil
              @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
              @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
              return if sopts.empty? and lopts.empty? # completely hidden
        Severity: Minor
        Found in samples/smelly_source/optparse.rb - About 2 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 parse_in_order has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def parse_in_order(argv = default_argv, setter = nil, &nonopt)  # :nodoc:
            opt, arg, sw, val, rest = nil
            nonopt ||= proc {|arg| throw :terminate, arg}
            argv.unshift(arg) if arg = catch(:terminate) {
              while arg = argv.shift
        Severity: Major
        Found in samples/smelly_source/optparse.rb - About 2 hrs to fix

          Method getopts has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def getopts(*args)
              argv = Array === args.first ? args.shift : default_argv
              single_options, *long_options = *args
          
              result = {}
          Severity: Minor
          Found in samples/smelly_source/optparse.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 complete has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def complete(key, icase = false, pat = nil)
                pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
                                   icase)
                canon, sw, k, v, cn = nil
                candidates = []
          Severity: Minor
          Found in samples/smelly_source/optparse.rb - About 1 hr to fix

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

                def parse_arg(arg)
                  pattern or return nil, arg
                  unless m = pattern.match(arg)
                    yield(InvalidArgument, arg)
                    return arg, nil
            Severity: Minor
            Found in samples/smelly_source/optparse.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 initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def initialize(pattern = nil, conv = nil,
                               short = nil, long = nil, arg = nil,
                               desc = ([] if short or long), block = Proc.new)
            Severity: Major
            Found in samples/smelly_source/optparse.rb - About 50 mins to fix

              Avoid deeply nested control flow statements.
              Open

                            rescue InvalidOption
                              # if no short options match, try completion with long
                              # options.
                              sw, = complete(:long, opt)
                              eq ||= !rest
              Severity: Major
              Found in samples/smelly_source/optparse.rb - About 45 mins to fix

                Method summarize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
                Severity: Minor
                Found in samples/smelly_source/optparse.rb - About 35 mins to fix

                  Method update has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
                  Severity: Minor
                  Found in samples/smelly_source/optparse.rb - About 35 mins to fix

                    Method complete has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def complete(id, opt, icase = false, *pat, &block)
                    Severity: Minor
                    Found in samples/smelly_source/optparse.rb - About 35 mins to fix

                      Method summarize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
                      Severity: Minor
                      Found in samples/smelly_source/optparse.rb - About 35 mins to fix

                        Avoid too many return statements within this method.
                        Open

                              return arg[s.length..-1], m
                        Severity: Major
                        Found in samples/smelly_source/optparse.rb - About 30 mins to fix

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

                              def add_banner(to)  # :nodoc:
                                unless @short or @long
                                  s = desc.join
                                  to << " [" + s + "]..." unless s.empty?
                                end
                          Severity: Minor
                          Found in samples/smelly_source/optparse.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

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

                                def parse(arg, argv, &error)
                                  if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
                                    return nil, block, nil
                                  end
                                  opt = (val = parse_arg(val, &error))[1]
                          Severity: Minor
                          Found in samples/smelly_source/optparse.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