senseobservationsystems/commonsense-ruby-lib

View on GitHub

Showing 19 of 19 total issues

Class Session has 26 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Session
    attr_accessor :logger, :base_uri

    def initialize(opts={})
      options = {
Severity: Minor
Found in lib/cs/session.rb - About 3 hrs to fix

    Method process_param_integer has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_param_integer(name, value, param_option)
          if value.kind_of?(Integer)
            retval = value
            retval = process_valid_values(name, value, param_option) if param_option[:valid_values]
            maximum = param_option[:maximum]
    Severity: Minor
    Found in lib/cs/parameter_processor.rb - About 45 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 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def initialize(consumer_key, consumer_secret, access_token, access_token_secret, uri=nil)
    Severity: Minor
    Found in lib/cs/auth/oauth.rb - About 35 mins to fix

      Method execute has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def execute(type, path, body, headers, &block)
      Severity: Minor
      Found in lib/cs/session.rb - About 35 mins to fix

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

            def retry_on_509(&block)
              while true
                response = yield
                if response_code == 509
                  waitfor = Random.new.rand(30..45)
        Severity: Minor
        Found in lib/cs/session.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 parse_data_structure has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse_data_structure
                if self.data_type == "json"
                  if self.data_structure && self.data_structure.kind_of?(String)
                    self.data_structure = JSON.parse(self.data_structure) rescue nil
                  end
        Severity: Minor
        Found in lib/cs/end_point/sensor.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 parse_response has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse_response(response)
                @response_body = response.content_type == "application/json" ? (JSON(response.body) rescue nil) : response.body
                @response_code = response.code.to_i
        
                @response_headers = response.to_hash
        Severity: Minor
        Found in lib/cs/auth/oauth.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 3 locations. Consider refactoring.
        Open

          module Relation
            class UserRelation
              include Relation
        
              parameter :page, Integer, default: 0, required: true
        Severity: Minor
        Found in lib/cs/relation/user_relation.rb and 2 other locations - About 30 mins to fix
        lib/cs/relation/notification_relation.rb on lines 2..16
        lib/cs/relation/trigger_relation.rb on lines 2..17

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

          module Relation
            class NotificationRelation
              include Relation
        
              parameter :page, Integer, default: 0, required: true
        Severity: Minor
        Found in lib/cs/relation/notification_relation.rb and 2 other locations - About 30 mins to fix
        lib/cs/relation/trigger_relation.rb on lines 2..17
        lib/cs/relation/user_relation.rb on lines 2..16

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

          module Relation
            class TriggerRelation
              include Relation
        
              parameter :page, Integer, default: 0, required: true
        Severity: Minor
        Found in lib/cs/relation/trigger_relation.rb and 2 other locations - About 30 mins to fix
        lib/cs/relation/notification_relation.rb on lines 2..16
        lib/cs/relation/user_relation.rb on lines 2..16

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

            def each_batch(params={}, &block)
              check_session!
              options = get_options(params)
        
              self.page ||= 0;
        Severity: Minor
        Found in lib/cs/relation.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 process_param_boolean has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def process_param_boolean(name, value, param_option)
              retval = nil
        
              if value.nil?
                retval = param_option[:default] ? param_option[:default] : nil
        Severity: Minor
        Found in lib/cs/parameter_processor.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 process_batch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def process_batch(batch)
                sensors = {}
                batch.each do |point|
                  next if point.nil? || point.sensor_id.nil?
                  sensor_id = point.sensor_id
        Severity: Minor
        Found in lib/cs/collection/sensor_data_collection.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 get_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_options(input={})
              options = {}
        
              self.class.parameters.each do |name, param_option|
                value = self.parameter(name) # get value from object
        Severity: Minor
        Found in lib/cs/relation.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 retrieve! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def retrieve!
              check_session!
              raise Error::ResourceIdError unless @id
        
              res = session.get(get_url)
        Severity: Minor
        Found in lib/cs/end_point.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 find_or_new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def find_or_new(attribute)
              check_session!
        
              self.each do |resource|
                found = true
        Severity: Minor
        Found in lib/cs/relation.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 to_cs_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def to_cs_value
                param = self.to_h(false)
                param.delete(:sensor_id)
                value = param[:value]
                if value
        Severity: Minor
        Found in lib/cs/end_point/sensor_data.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 get(path, query={}, headers = {})
                execute do
                  path += '?' + URI.encode_www_form(query) unless query.empty?
                  @request_headers = default_headers.merge(headers)
                  oauth.get(path, headers)
        Severity: Minor
        Found in lib/cs/auth/oauth.rb and 1 other location - About 20 mins to fix
        lib/cs/auth/oauth.rb on lines 55..59

        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 delete(path, query={}, headers = {})
                execute do
                  path += '?' + URI.encode_www_form(query) unless query.empty?
                  @request_headers = default_headers.merge(headers)
                  oauth.delete(path, headers)
        Severity: Minor
        Found in lib/cs/auth/oauth.rb and 1 other location - About 20 mins to fix
        lib/cs/auth/oauth.rb on lines 31..35

        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