paidapi/paid-ruby

View on GitHub

Showing 13 of 13 total issues

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

  class OrderItem < APIResource
    attr_reader :id
    attr_reader :object
    attr_accessor :order
    attr_accessor :plan_item
Severity: Major
Found in lib/paid/order_item.rb and 1 other location - About 4 hrs to fix
lib/paid/product.rb on lines 2..52

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

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

  class Product < APIResource
    attr_reader :id
    attr_reader :object
    attr_accessor :description
    attr_accessor :external_id
Severity: Major
Found in lib/paid/product.rb and 1 other location - About 4 hrs to fix
lib/paid/order_item.rb on lines 2..51

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

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 run_transaction_tests has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run_transaction_tests(customer)
    puts "Creating 2 transactions with customer=#{customer.id}"
    transaction = Paid::Transaction.create({
      :amount => 100,
      :description => 'a description',
Severity: Minor
Found in tasks/api_test.rb - About 1 hr to fix

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

        def refresh_from(json, api_method=nil)
          unless json.is_a?(Hash)
            json = {
              :data => json
            }
    Severity: Minor
    Found in lib/paid/api_list.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 query_array has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.query_array(params, key_prefix=nil)
          ret = []
          params.each do |key, value|
            if params.is_a?(Array)
              value = key
    Severity: Minor
    Found in lib/paid/requester.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 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.symbolize_keys(obj)
          if obj.is_a?(Hash)
            ret = {}
            obj.each do |key, value|
              ret[(key.to_sym rescue key) || key] = symbolize_keys(value)
    Severity: Minor
    Found in lib/paid/util.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 prepare_params has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.prepare_params(url, params, method)
          if [:get, :head, :delete].include?(method)
            unless params.empty?
              url += URI.parse(url).query ? '&' : '?' + query_string(params)
            end
    Severity: Minor
    Found in lib/paid/requester.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 initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize(method, path, params, headers, object, api_key=nil, api_base=nil)
    Severity: Major
    Found in lib/paid/api_method.rb - About 50 mins to fix

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

          def self.sorta_deep_clone(json)
            if json.is_a?(Hash)
              ret = {}
              json.each do |k, v|
                ret[k] = sorta_deep_clone(v)
      Severity: Minor
      Found in lib/paid/util.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 build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.build(path, object, params)
            ret = path.dup
            if ret.include?(":")
              matches = ret.scan(/:([^\/]*)/).flatten.map(&:to_sym)
              missing = Set.new(matches)
      Severity: Minor
      Found in lib/paid/path_builder.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 determine_api_attribute_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.determine_api_attribute_value(name, raw_value)
            if @api_attributes[name] && @api_attributes[name].has_key?(:constructor)
              klass = Util.constantize(@api_attributes[name][:constructor])
              if(klass.respond_to?(:construct))
                klass.construct(raw_value)
      Severity: Minor
      Found in lib/paid/api_resource.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

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

          def invoices(params={}, headers={})
            params = ParamsBuilder.merge(params, {
              :customer => self.id,
            })
            method = APIMethod.new(:get, "/invoices", params, headers, self)
      Severity: Minor
      Found in lib/paid/customer.rb and 1 other location - About 20 mins to fix
      lib/paid/customer.rb on lines 82..87

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

      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 transactions(params={}, headers={})
            params = ParamsBuilder.merge(params, {
              :customer => self.id,
            })
            method = APIMethod.new(:get, "/transactions", params, headers, self)
      Severity: Minor
      Found in lib/paid/customer.rb and 1 other location - About 20 mins to fix
      lib/paid/customer.rb on lines 74..79

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

      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

      Severity
      Category
      Status
      Source
      Language