cybernetlab/ensure_it

View on GitHub

Showing 24 of 35 total issues

Method ensure_name has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    def self.ensure_name(str, name_of: nil, **opts)
      str = str.ensure_string!
      name_of = name_of.ensure_symbol(
        downcase: true,
        values: NAME_TYPES,
Severity: Minor
Found in lib/ensure_it/string_utils.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 ensure_array has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

    def self.ensure_array(arr, *args, values: nil, **opts)
      args.each do |arg|
        if arg.is_a?(Proc)
          arr = arr.map(arg)
          next
Severity: Minor
Found in lib/ensure_it/ensure_array.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 ensure_array has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    def self.ensure_array(arr, *args, values: nil, **opts)
      args.each do |arg|
        if arg.is_a?(Proc)
          arr = arr.map(arg)
          next
Severity: Minor
Found in lib/ensure_it/ensure_array.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

Method ensure_name has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.ensure_name(str, name_of: nil, **opts)
      str = str.ensure_string!
      name_of = name_of.ensure_symbol(
        downcase: true,
        values: NAME_TYPES,
Severity: Major
Found in lib/ensure_it/string_utils.rb - About 2 hrs to fix

    Method activate_smart_errors has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.activate_smart_errors(error, **opts)
        tp_count = 0
        error_obj = nil
        #
        # first trace point is to capture raise object before exitting
    Severity: Minor
    Found in lib/ensure_it/errors.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 ensure_array has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.ensure_array(arr, *args, values: nil, **opts)
          args.each do |arg|
            if arg.is_a?(Proc)
              arr = arr.map(arg)
              next
    Severity: Minor
    Found in lib/ensure_it/ensure_array.rb - About 1 hr to fix

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

          def subject_display_name
            display_name =
              if @subject.nil? && @subject_type != :unknown_method_result
                "subject of '#{method_name}' method"
              else
      Severity: Minor
      Found in lib/ensure_it/errors.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 subject_display_name has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def subject_display_name
            display_name =
              if @subject.nil? && @subject_type != :unknown_method_result
                "subject of '#{method_name}' method"
              else
      Severity: Minor
      Found in lib/ensure_it/errors.rb - About 1 hr to fix

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

            def ensure_integer!(boolean: nil, **opts)
              if boolean == true || boolean.is_a?(Integer)
                value = boolean == true ? 1 : boolean
                return value if opts.empty?
                catch(:wrong) { return EnsureIt.ensure_integer(value, **opts) }
        Severity: Minor
        Found in lib/ensure_it/ensure_integer.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 ensure_integer has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def ensure_integer(default: nil, boolean: nil, **opts)
              if boolean == true || boolean.is_a?(Integer)
                value = boolean == true ? 1 : boolean
                return value if opts.empty?
                catch(:wrong) { return EnsureIt.ensure_integer(value, **opts) }
        Severity: Minor
        Found in lib/ensure_it/ensure_integer.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 inspect_source has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.inspect_source(error, **opts)
            file_name, line_no = error.backtrace.first.split(':', 2)
            return unless File.exist?(file_name)
            line_no = line_no.to_i
            line = read_line_number(file_name, line_no)
        Severity: Minor
        Found in lib/ensure_it/errors.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 ensure_symbol has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.ensure_symbol(sym, values: nil, downcase: nil, name_of: nil, **opts)
            if name_of.nil?
              value = downcase == true ? sym.to_s.downcase.to_sym : sym
            else
              value = EnsureIt::StringUtils.ensure_name(
        Severity: Minor
        Found in lib/ensure_it/ensure_symbol.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 ensure_string has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.ensure_string(str, values: nil, downcase: nil, name_of: nil, **opts)
            if name_of.nil?
              value = downcase == true ? str.downcase : str
            else
              value = EnsureIt::StringUtils.ensure_name(
        Severity: Minor
        Found in lib/ensure_it/ensure_string.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 ensure_string_error has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.ensure_string_error(**opts)
            unless opts.key?(:message)
              opts[:message] = '#{subject} should be a String or a Symbol'
              if opts[:numbers] == true
                opts[:message] << ' or a Numeric'
        Severity: Minor
        Found in lib/ensure_it/ensure_string.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 ensure_class! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def ensure_class!(*args, strings: nil, **opts)
              if strings == true
                catch :wrong do
                  return EnsureIt.ensure_class_string(self, *args, **opts)
                end
        Severity: Minor
        Found in lib/ensure_it/ensure_class.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

        Avoid too many return statements within this method.
        Open

                return nil if m.nil?
        Severity: Major
        Found in lib/ensure_it/string_utils.rb - About 30 mins to fix

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

            def self.ensure_symbol_error(**opts)
              unless opts.key?(:message)
                opts[:message] = '#{subject} should be a Symbol or a String'
                if opts.key?(:name_of)
                  opts[:message] << " and should be a name of #{opts[:name_of]}"
          Severity: Minor
          Found in lib/ensure_it/ensure_symbol.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 ensure_instance_of has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def ensure_instance_of(klass, default: nil, **opts)
                unless klass.is_a?(Class)
                  fail(
                    ArgumentError,
                    'Wrong class argument for #ensure_instance_of specified'
          Severity: Minor
          Found in lib/ensure_it/ensure_instance_of.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 ensure_boolean has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def ensure_boolean(default: nil, numbers: true, positive: false, **opts)
                return positive == true ? self > 0 : self != 0 if numbers == true
                default
              end
          Severity: Minor
          Found in lib/ensure_it/ensure_boolean.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 message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def message
                unless @message.is_a?(String)
                  @message =
                    if @subject.nil? && @subject_type != :unknown_method_result
                      '#{subject}'
          Severity: Minor
          Found in lib/ensure_it/errors.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