cybernetlab/ensure_it

View on GitHub

Showing 35 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

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

          patch Integer do
            def ensure_float(default: nil, **opts)
              return to_f if opts.nil?
              catch(:wrong) { return EnsureIt.ensure_float(to_f, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_float.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 61..72
        lib/ensure_it/ensure_integer.rb on lines 41..52
        lib/ensure_it/ensure_integer.rb on lines 56..67
        lib/ensure_it/ensure_string.rb on lines 86..101
        lib/ensure_it/ensure_symbol.rb on lines 13..28

        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 3 locations. Consider refactoring.
        Open

          patch String do
            def ensure_string(default: nil, **opts)
              return self if opts.empty?
              catch :wrong do
                return EnsureIt.ensure_string(self, **opts)
        Severity: Major
        Found in lib/ensure_it/ensure_string.rb and 2 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 46..57
        lib/ensure_it/ensure_integer.rb on lines 26..37

        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 6 locations. Consider refactoring.
        Open

          patch String do
            def ensure_symbol(default: nil, **opts)
              return to_sym if opts.empty?
              catch :wrong do
                return EnsureIt.ensure_symbol(to_sym, **opts)
        Severity: Major
        Found in lib/ensure_it/ensure_symbol.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 31..42
        lib/ensure_it/ensure_float.rb on lines 61..72
        lib/ensure_it/ensure_integer.rb on lines 41..52
        lib/ensure_it/ensure_integer.rb on lines 56..67
        lib/ensure_it/ensure_string.rb on lines 86..101

        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 6 locations. Consider refactoring.
        Open

          patch Rational do
            def ensure_integer(default: nil, **opts)
              return round if opts.empty?
              catch(:wrong) { return EnsureIt.ensure_integer(round, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_integer.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 31..42
        lib/ensure_it/ensure_float.rb on lines 61..72
        lib/ensure_it/ensure_integer.rb on lines 41..52
        lib/ensure_it/ensure_string.rb on lines 86..101
        lib/ensure_it/ensure_symbol.rb on lines 13..28

        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 3 locations. Consider refactoring.
        Open

          patch Integer do
            def ensure_integer(default: nil, **opts)
              return self if opts.empty?
              catch(:wrong) { return EnsureIt.ensure_integer(self, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_integer.rb and 2 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 46..57
        lib/ensure_it/ensure_string.rb on lines 67..82

        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 3 locations. Consider refactoring.
        Open

          patch Float do
            def ensure_float(default: nil, **opts)
              return self if opts.nil?
              catch(:wrong) { return EnsureIt.ensure_float(self, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_float.rb and 2 other locations - About 1 hr to fix
        lib/ensure_it/ensure_integer.rb on lines 26..37
        lib/ensure_it/ensure_string.rb on lines 67..82

        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 6 locations. Consider refactoring.
        Open

          patch Float do
            def ensure_integer(default: nil, **opts)
              return round if opts.empty?
              catch(:wrong) { return EnsureIt.ensure_integer(round, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_integer.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 31..42
        lib/ensure_it/ensure_float.rb on lines 61..72
        lib/ensure_it/ensure_integer.rb on lines 56..67
        lib/ensure_it/ensure_string.rb on lines 86..101
        lib/ensure_it/ensure_symbol.rb on lines 13..28

        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 6 locations. Consider refactoring.
        Open

          patch Symbol do
            def ensure_string(default: nil, **opts)
              return to_s if opts.empty?
              catch :wrong do
                return EnsureIt.ensure_string(to_s, **opts)
        Severity: Major
        Found in lib/ensure_it/ensure_string.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 31..42
        lib/ensure_it/ensure_float.rb on lines 61..72
        lib/ensure_it/ensure_integer.rb on lines 41..52
        lib/ensure_it/ensure_integer.rb on lines 56..67
        lib/ensure_it/ensure_symbol.rb on lines 13..28

        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 6 locations. Consider refactoring.
        Open

          patch Rational do
            def ensure_float(default: nil, **opts)
              return to_f if opts.nil?
              catch(:wrong) { return EnsureIt.ensure_float(to_f, **opts) }
              default
        Severity: Major
        Found in lib/ensure_it/ensure_float.rb and 5 other locations - About 1 hr to fix
        lib/ensure_it/ensure_float.rb on lines 31..42
        lib/ensure_it/ensure_integer.rb on lines 41..52
        lib/ensure_it/ensure_integer.rb on lines 56..67
        lib/ensure_it/ensure_string.rb on lines 86..101
        lib/ensure_it/ensure_symbol.rb on lines 13..28

        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 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

        Severity
        Category
        Status
        Source
        Language