contactually/zuora-ruby

View on GitHub

Showing 10 of 10 total issues

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

    def handle_errors(hash)
      errors = []

      hash.each do |key, value|
        if value.is_a?(Hash)
Severity: Minor
Found in lib/zuora/response.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_schema has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def ensure_schema(value, child_schema)
      if value.present? && child_schema.present?
        value = if child_schema.is_a?(Array)
                  value.map do |item|
                    item.is_a?(SchemaModel) ? item : child_schema[0].new(item)
Severity: Minor
Found in lib/utils/schema_model.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 fail_or_response has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def fail_or_response(response)
        if response.status != 200
          raise(ErrorResponse.new("HTTP Status #{response.status}", response))
        elsif response.body.kind_of?(Array)
          if !response.body.first['Success']
Severity: Minor
Found in lib/zuora/rest/client.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 symbolize_keys_deep has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def symbolize_keys_deep(hash)
      return hash unless hash.is_a?(Hash)

      Hash[hash.map do |key, value|
        # if value is array, loop each element and recursively symbolize keys
Severity: Minor
Found in lib/zuora/response.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

Method query_to_string has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def query_to_string(fields, table, conditions)
        raise 'Fields must be an Array' unless fields.is_a?(Array)
        raise 'Table must respond to :to_sym' unless table.respond_to?(:to_sym)
        raise 'Conditions must be Array' if fields && !fields.is_a?(Array)

Severity: Minor
Found in lib/zuora/calls/query.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

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

      def parse_error(body)
        message = ""
        if body['reasons']
          reasons = body['reasons'].map do |reason|
            "Error #{reason['code']}: #{reason['message']}"
Severity: Minor
Found in lib/zuora/rest/client.rb and 1 other location - About 30 mins to fix
lib/zuora/rest/client.rb on lines 132..140

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

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

      def parse_legacy_error(body)
        message = ""
        if body['Errors']
          errors = body['Errors'].map do |error|
            "Error #{error['Code']}: #{error['Message']}"
Severity: Minor
Found in lib/zuora/rest/client.rb and 1 other location - About 30 mins to fix
lib/zuora/rest/client.rb on lines 117..125

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

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 xml has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.xml(header, body)
        Nokogiri::XML::Builder.new do |builder|
          builder[:soapenv].Envelope(Zuora::NAMESPACES) do
            builder[:soapenv].Header { header.call builder } if header
            builder[:soapenv].Body { body.call builder } if body
Severity: Minor
Found in lib/zuora/utils/envelope.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 api_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def api_url(sandbox)
        if use_modern_rest?
          sandbox ? Zuora::Rest::NEWEST_SANDBOX_URL : Zuora::Rest::NEWEST_API_URL
        else
          sandbox ? Zuora::Rest::SANDBOX_URL : Zuora::Rest::API_URL
Severity: Minor
Found in lib/zuora/rest/client.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 check_validation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def check_validation(valid, value)
      return unless valid && value

      passes_validation = begin
                            valid.call(value)
Severity: Minor
Found in lib/utils/schema_model.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