cwadding/foscam-ruby

View on GitHub
lib/foscam/client.rb

Summary

Maintainability
F
4 days
Test Coverage

Method group_params has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

        def self.group_params(params = {})
            grouped_params = {}
            params.each do |field, value|

            # next if segment_from_hash(field.to_s, value, /ntp_(.+)/, :ntp, grouped_params)
Severity: Minor
Found in lib/foscam/client.rb - About 1 day 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 camera_control has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

        def camera_control(params)
            params.all? do |key, value|
                # validation
                case key
                when :resolution
Severity: Minor
Found in lib/foscam/client.rb - About 7 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 Client has 33 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Client

        # @!attribute [rw] connection
        #   @return [Faraday] The HTTP connection object to the camera        
        attr_accessor :connection
Severity: Minor
Found in lib/foscam/client.rb - About 4 hrs to fix

    File client.rb has 303 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "foscam/constants"
    module Foscam
        class Client
    
            # @!attribute [rw] connection
    Severity: Minor
    Found in lib/foscam/client.rb - About 3 hrs to fix

      Method segment_from_hash has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              def self.segment_from_hash(str, value, regexp, new_key, dst = {}, &block)
                  # throw TypeError, "Argument 1 [str] is a #{str.class.to_s}. Expected a String." unless str.is_a?(String)
                  # throw TypeError, "Argument 3 [regexp] is a #{regexp.class.to_s}. Expected a Regexp/" unless regexp.is_a?(Regexp)
                  # throw TypeError, "Argument 4 [new_key] is a #{new_key.class.to_s}. Expected a String or Symbol." unless new_key.is_a?(String) || new_key.is_a?(Symbol)
                  # throw TypeError, "Argument 5 [dst] is a #{dst.class.to_s}. Expected a Hash" unless dst.is_a?(Hash)  
      Severity: Minor
      Found in lib/foscam/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 camera_control has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def camera_control(params)
                  params.all? do |key, value|
                      # validation
                      case key
                      when :resolution
      Severity: Minor
      Found in lib/foscam/client.rb - About 1 hr to fix

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

                def set_misc(params)
                    url_params = params.clone
                    [:ptz_patrol_rate, :ptz_patrol_up_rate, :ptz_patrol_down_rate, :ptz_patrol_left_rate, :ptz_patrol_right_rate].each do |key|
                        throw "invalid parameter value" if (url_params.has_key?(key) && (url_params[key].to_i < 0 || url_params[key].to_i > 100))
                    end
        Severity: Minor
        Found in lib/foscam/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 group_params has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def self.group_params(params = {})
                    grouped_params = {}
                    params.each do |field, value|
        
                    # next if segment_from_hash(field.to_s, value, /ntp_(.+)/, :ntp, grouped_params)
        Severity: Minor
        Found in lib/foscam/client.rb - About 1 hr to fix

          Method segment_from_hash has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  def self.segment_from_hash(str, value, regexp, new_key, dst = {}, &block)
          Severity: Minor
          Found in lib/foscam/client.rb - About 45 mins to fix

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

                    def get_forbidden
                        response = @connection.get("get_forbidden.cgi")
                        params = response.success? ? parse_response(response) : {}
                        schedule = {}
                        unless params.empty?
            Severity: Minor
            Found in lib/foscam/client.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

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

                            when :mode
                                case value
                                when Integer
                                    throw "invalid parameter value" if value.to_i < 0 || value.to_i > 2
                                when Symbol || String
            Severity: Major
            Found in lib/foscam/client.rb and 1 other location - About 1 hr to fix
            lib/foscam/client.rb on lines 122..130

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

            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

                            when :flip
                                case value
                                when Integer
                                    throw "invalid parameter value" if value.to_i < 0 || value.to_i > 3
                                when String || Symbol
            Severity: Major
            Found in lib/foscam/client.rb and 1 other location - About 1 hr to fix
            lib/foscam/client.rb on lines 112..120

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

            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

                        next if segment_from_hash(field.to_s, value, /ftp_(.+)/, :ftp, grouped_params) do |matches, val, h|
                            h.merge!(matches.to_a[1..matches.size].join("_").to_sym => val) unless segment_from_hash(matches.to_a[1..matches.size].join("_").to_s, val, /schedule_(.+)/, :schedule, h)
                            h
            Severity: Minor
            Found in lib/foscam/client.rb and 1 other location - About 50 mins to fix
            lib/foscam/client.rb on lines 657..659

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

            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

                        next if segment_from_hash(field.to_s, value, /alarm_(.+)/, :alarm, grouped_params) do |matches, val, h|
                            h.merge!(matches.to_a[1..matches.size].join("_").to_sym => val) unless segment_from_hash(matches.to_a[1..matches.size].join("_").to_s, val, /schedule_(.+)/, :schedule, h)
                            h
            Severity: Minor
            Found in lib/foscam/client.rb and 1 other location - About 50 mins to fix
            lib/foscam/client.rb on lines 662..664

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

            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