coding-chimp/onesignal

View on GitHub
lib/onesignal/models/notification200_errors.rb

Summary

Maintainability
D
1 day
Test Coverage

Method find_and_cast_into_type has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

      def find_and_cast_into_type(klass, data)
        return if data.nil?

        case klass.to_s
        when 'Boolean'
Severity: Minor
Found in lib/onesignal/models/notification200_errors.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 find_and_cast_into_type has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def find_and_cast_into_type(klass, data)
        return if data.nil?

        case klass.to_s
        when 'Boolean'
Severity: Minor
Found in lib/onesignal/models/notification200_errors.rb - About 1 hr to fix

    Method build has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def build(data)
            # Go through the list of oneOf items and attempt to identify the appropriate one.
            # Note:
            # - We do not attempt to check whether exactly one item matches.
            # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
    Severity: Minor
    Found in lib/onesignal/models/notification200_errors.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

    Avoid too many return statements within this method.
    Open

              return Date.parse(data)
    Severity: Major
    Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                return Time.parse(data)
      Severity: Major
      Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
        Severity: Major
        Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return data.map { |item| find_and_cast_into_type(sub_type, item) }
          Severity: Major
          Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return data if data.instance_of?(String)
            Severity: Major
            Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                            return model if model && model.valid?
              Severity: Major
              Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                          return data if data.instance_of?(Hash)
                Severity: Major
                Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                return model if model
                  Severity: Major
                  Found in lib/onesignal/models/notification200_errors.rb - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status