cwadding/foscam-ruby

View on GitHub

Showing 35 of 35 total issues

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

                    def to_hash
                        h = {}
                        h.merge!({:ntp_svr        => self.ntp_svr }) unless ntp_svr.nil?
                        h.merge!({:ntp_enable     => self.ntp_enable ? "1" : "0" }) unless ntp_enable.nil?
                        h.merge!({:now             => self.time.to_i, :tz => -self.time.utc_offset }) unless time.nil?
        Severity: Minor
        Found in lib/foscam/model/clock.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 to_hash has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                    def to_hash
                        result = [:ssid, :wpa_psk].inject({}) do |h, key|
                            h.merge!({key => send(key) }) unless send(key).nil?
                            h
                        end
        Severity: Minor
        Found in lib/foscam/model/wifi_config.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 dirty_params_hash has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                    def dirty_params_hash
                        h = {}
                        h.merge!({:motion_armed         => self.motion_armed }) if motion_armed_changed?
                        h.merge!({:motion_sensitivity     => self.motion_sensitivity }) if motion_sensitivity_changed?
                        h.merge!({:motion_compensation     => self.motion_compensation }) if motion_compensation_changed?
        Severity: Minor
        Found in lib/foscam/activemodel/alarm_config.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 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

        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

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

                    def set_id
                        flag = false
                        if @id.nil?
                            cam_params = client.get_params
                            unless cam_params.empty?
        Severity: Minor
        Found in lib/foscam/activemodel/user.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 client= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                    def client=(obj)
                        unless obj.nil?
                            MailServer::client = obj
                            params = client.get_params
                            unless params.empty?
        Severity: Minor
        Found in lib/foscam/activemodel/mail_server.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

        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

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

                      def initialize(params = {})
                          self.days = {}
                          [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday].each do |day|
                              abbrev = day.to_s[0..2]
                              bit0 = params.has_key?("#{abbrev}_0".to_sym) ? params["#{abbrev}_0".to_sym] : 0
          Severity: Minor
          Found in lib/foscam/schedule/week.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

          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

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

                  def connect(params = {})
                      @url = params[:url] if params.has_key?(:url)
                      @username = params[:username] if params.has_key?(:username)
                      @password = params[:password] if params.has_key?(:password)
                      @connection = Faraday.new( :url => @url) unless @url.nil?
          Severity: Minor
          Found in lib/foscam/connection.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 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
            Severity
            Category
            Status
            Source
            Language