adelevie/parse_resource

View on GitHub

Showing 24 of 24 total issues

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

        def turn_relation_hash_into_object(hash)
          return nil if hash == nil or hash["className"] == "_User"
          relation_object = hash["className"].to_s.constantize.new if hash["className"] != "_User"
          hash.each do |key, value|
            class_name_in_a_hash = false
      Severity: Minor
      Found in lib/parse_resource/query.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

      Class Query has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Query
      
        def initialize(klass)
          @klass = klass
        end
      Severity: Minor
      Found in lib/parse_resource/query.rb - About 2 hrs to fix

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

              def initialize(code, msg="")
                @msg = msg
                @code = code
                case code.to_s
                when "111"
            Severity: Minor
            Found in lib/parse_resource/parse_error.rb - About 1 hr to fix

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

                def remove_user(user)
                  # Expects user parameter to be a ParseUser object
                  
                  base_uri   = "https://api.parse.com/1/roles/#{self.objectId}"
                  app_id     = self.class.settings['app_id']
              Severity: Major
              Found in lib/parse_resource/parse_role.rb and 1 other location - About 1 hr to fix
              lib/parse_resource/parse_role.rb on lines 31..45

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

              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 add_user(user)
                  # Expects user parameter to be a ParseUser object
                  base_uri   = "https://api.parse.com/1/roles/#{self.objectId}"
                  app_id     = self.class.settings['app_id']
                  master_key = self.class.settings['master_key']
              Severity: Major
              Found in lib/parse_resource/parse_role.rb and 1 other location - About 1 hr to fix
              lib/parse_resource/parse_role.rb on lines 49..64

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

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

                  def execute
                    if @klass.has_many_relations
                      relations = @klass.has_many_relations.map { |relation| relation.to_s }
                      include_object(relations)
                    end
                Severity: Minor
                Found in lib/parse_resource/query.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 turn_relation_hash_into_object has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def turn_relation_hash_into_object(hash)
                    return nil if hash == nil or hash["className"] == "_User"
                    relation_object = hash["className"].to_s.constantize.new if hash["className"] != "_User"
                    hash.each do |key, value|
                      class_name_in_a_hash = false
                Severity: Minor
                Found in lib/parse_resource/query.rb - About 1 hr to fix

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

                    def get_relation_objects(objects)
                      if @klass.has_many_relations
                        objects.each do |item|
                          @klass.has_many_relations.each do |relation|
                            item.attributes[relation.to_s] = [] if !item.attributes.has_key?(relation.to_s)
                  Severity: Minor
                  Found in lib/parse_resource/query.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 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 exists? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def exists?(query)
                      each do |item|
                        conditions_met = true
                        item.attributes.each do |key, value|
                          conditions_met = false if query.has_key?(key) and query[key] != value
                  Severity: Minor
                  Found in lib/parse_resource/relation_array.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 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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language