adelevie/parse_resource

View on GitHub
lib/parse_resource/base.rb

Summary

Maintainability
F
4 days
Test Coverage

Class Base has 61 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Base
    # ParseResource::Base provides an easy way to use Ruby to interace with a Parse.com backend
    # Usage:
    #  class Post < ParseResource::Base
    #    fields :title, :author, :body
Severity: Major
Found in lib/parse_resource/base.rb - About 1 day to fix

    File base.rb has 509 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "rubygems"
    require "bundler/setup"
    require "active_model"
    require "erb"
    require "rest-client"
    Severity: Major
    Found in lib/parse_resource/base.rb - About 1 day to fix

      Method relations_for_saving has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def relations_for_saving(put_attrs)
            all_add_item_queries = {}
            all_remove_item_queries = {}
            @unsaved_attributes.each_pair do |key, value|
              next if !value.is_a? Array
      Severity: Minor
      Found in lib/parse_resource/base.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 batch_save has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.batch_save(save_objects, slice_size = 20, method = nil)
            return true if save_objects.blank?
            load_settings
      
            base_uri = "https://api.parse.com/1/batch"
      Severity: Minor
      Found in lib/parse_resource/base.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 get_attribute has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_attribute(k)
            attrs = @unsaved_attributes[k.to_s] ? @unsaved_attributes : @attributes
            case attrs[k]
            when Hash
              klass_name = attrs[k]["className"]
      Severity: Minor
      Found in lib/parse_resource/base.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 relations_for_saving has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def relations_for_saving(put_attrs)
            all_add_item_queries = {}
            all_remove_item_queries = {}
            @unsaved_attributes.each_pair do |key, value|
              next if !value.is_a? Array
      Severity: Minor
      Found in lib/parse_resource/base.rb - About 1 hr to fix

        Method get_attribute has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_attribute(k)
              attrs = @unsaved_attributes[k.to_s] ? @unsaved_attributes : @attributes
              case attrs[k]
              when Hash
                klass_name = attrs[k]["className"]
        Severity: Minor
        Found in lib/parse_resource/base.rb - About 1 hr to fix

          Method batch_save has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.batch_save(save_objects, slice_size = 20, method = nil)
                return true if save_objects.blank?
                load_settings
          
                base_uri = "https://api.parse.com/1/batch"
          Severity: Minor
          Found in lib/parse_resource/base.rb - About 1 hr to fix

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

                def save
                  if valid?
                    run_callbacks :save do
                      if new?
                        create
            Severity: Minor
            Found in lib/parse_resource/base.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 upload has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.upload(file_instance, filename, options={})
                  load_settings
            
                  base_uri = "https://api.parse.com/1/files"
            
            
            Severity: Minor
            Found in lib/parse_resource/base.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 post_result has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def post_result(resp, req, res, &block)
                  if resp.code.to_s == "200" || resp.code.to_s == "201"
                    puts "request: #{req.inspect}"
                    merge_attributes(JSON.parse(resp))
            
            
            Severity: Minor
            Found in lib/parse_resource/base.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 4 locations. Consider refactoring.
            Open

                    attrib   = method_name.gsub(/^find_all_by_/,"")
                    finder_name = "find_all_by_#{attrib}"
            
                    define_singleton_method(finder_name) do |target_value|
                      where({attrib.to_sym => target_value}).all
            Severity: Minor
            Found in lib/parse_resource/base.rb and 3 other locations - About 15 mins to fix
            lib/parse_resource/base.rb on lines 133..140
            lib/parse_resource/query.rb on lines 188..195
            lib/parse_resource/query.rb on lines 198..205

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

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

                    attrib   = method_name.gsub(/^find_by_/,"")
                    finder_name = "find_all_by_#{attrib}"
            
                    define_singleton_method(finder_name) do |target_value|
                      where({attrib.to_sym => target_value}).first
            Severity: Minor
            Found in lib/parse_resource/base.rb and 3 other locations - About 15 mins to fix
            lib/parse_resource/base.rb on lines 143..150
            lib/parse_resource/query.rb on lines 188..195
            lib/parse_resource/query.rb on lines 198..205

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

            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

            There are no issues that match your filters.

            Category
            Status