WeAreFarmGeek/diplomat

View on GitHub

Showing 64 of 64 total issues

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

    def send_delete_request(connection, url, options, custom_params = nil)
      rest_options = parse_options(options)
      url += rest_options[:query_params]
      url += custom_params unless custom_params.nil?
      connection.delete do |req|
Severity: Minor
Found in lib/diplomat/rest_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

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

    def create(value, options = {})
      blacklist = ['ID', 'iD', 'Id', :ID, :iD, :Id] & value.keys
      raise Diplomat::RoleMalformed, 'ID should not be specified' unless blacklist.empty?

      id = value[:Name] || value['Name']
Severity: Minor
Found in lib/diplomat/role.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 register_ttl has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def register_ttl(check_id, name, notes, ttl, options = {})
Severity: Minor
Found in lib/diplomat/check.rb - About 35 mins to fix

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

        def send_post_request(connection, url, options, data, custom_params = nil)
    Severity: Minor
    Found in lib/diplomat/rest_client.rb - About 35 mins to fix

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

          def wait_to_acquire(key, session, value = nil, check_interval = 10, options = {})
      Severity: Minor
      Found in lib/diplomat/lock.rb - About 35 mins to fix

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

            def get(name = nil, token = :last, not_found = :wait, found = :return, options = {})
        Severity: Minor
        Found in lib/diplomat/event.rb - About 35 mins to fix

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

              def info(id, options = {})
                custom_params = []
                custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
                raw = send_get_request(@conn, ["/v1/session/info/#{id}"], options, custom_params)
                JSON.parse(raw.body).map { |session| OpenStruct.new session }
          Severity: Minor
          Found in lib/diplomat/session.rb and 1 other location - About 35 mins to fix
          lib/diplomat/session.rb on lines 70..74

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

          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 node(name, options = {})
                custom_params = []
                custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
                raw = send_get_request(@conn, ["/v1/session/node/#{name}"], options, custom_params)
                JSON.parse(raw.body).map { |session| OpenStruct.new session }
          Severity: Minor
          Found in lib/diplomat/session.rb and 1 other location - About 35 mins to fix
          lib/diplomat/session.rb on lines 59..63

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

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

            def self.consul_info(options = {})
              consul_self = Diplomat::Agent.self(options)
              puts 'Server: ' + consul_self['Config']['NodeName']
              puts 'Datacenter: ' + consul_self['Config']['Datacenter']
              puts 'Consul Version: ' + consul_self['Config']['Version']
          Severity: Minor
          Found in lib/diplomatic_bag/info.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_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_options(options)
                headers = nil
                query_params = []
                url_prefix = nil
                consistency = []
          Severity: Minor
          Found in lib/diplomat/rest_client.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

          Avoid too many return statements within this method.
          Open

                    return return_value(return_nil_values, transformation)
          Severity: Major
          Found in lib/diplomat/kv.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]
            Severity: Major
            Found in lib/diplomat/kv.rb - About 30 mins to fix

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

                  def get_all(options = {})
                    custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
                    ret = send_get_request(@conn, ['/v1/catalog/nodes'], options, custom_params)
                    JSON.parse(ret.body).map { |service| OpenStruct.new service }
              Severity: Minor
              Found in lib/diplomat/node.rb and 2 other locations - About 30 mins to fix
              lib/diplomat/nodes.rb on lines 18..21
              lib/diplomat/query.rb on lines 21..24

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

              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

                  def get_all(options = {})
                    custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
                    ret = send_get_request(@conn, ['/v1/query'], options, custom_params)
                    JSON.parse(ret.body).map { |query| OpenStruct.new query }
              Severity: Minor
              Found in lib/diplomat/query.rb and 2 other locations - About 30 mins to fix
              lib/diplomat/node.rb on lines 21..24
              lib/diplomat/nodes.rb on lines 18..21

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

              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

                  def get_all(options = {})
                    custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
                    ret = send_get_request(@conn, ['/v1/catalog/nodes'], options, custom_params)
                    JSON.parse(ret.body).map { |service| OpenStruct.new service }
              Severity: Minor
              Found in lib/diplomat/nodes.rb and 2 other locations - About 30 mins to fix
              lib/diplomat/node.rb on lines 21..24
              lib/diplomat/query.rb on lines 21..24

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

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

                  def create(value = nil, options = {})
                    # TODO: only certain keys are recognised in a session create request,
                    # should raise an error on others.
                    custom_params = []
                    custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
              Severity: Minor
              Found in lib/diplomat/session.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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update(value, options = {})
                    id = value[:ID] || value['ID']
                    raise Diplomat::IdParameterRequired if id.nil?
              
                    role_name = value[:Name] || value['Name']
              Severity: Minor
              Found in lib/diplomat/role.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_all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_all(name = nil, not_found = :reject, found = :return, options = {})
                    # Event list never returns 404 or blocks, but may return an empty list
                    @raw = send_get_request(@conn, ['/v1/event/list'], options, use_named_parameter('name', name))
                    if JSON.parse(@raw.body).count.zero?
                      case not_found
              Severity: Minor
              Found in lib/diplomat/event.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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update(value, options = {})
                    id = value[:ID] || value['ID']
                    raise Diplomat::IdParameterRequired if id.nil?
              
                    policy_name = value[:Name] || value['Name']
              Severity: Minor
              Found in lib/diplomat/policy.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 wait_to_acquire has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def wait_to_acquire(key, session, value = nil, check_interval = 10, options = {})
                    acquired = false
                    until acquired
                      acquired = acquire(key, session, value, options)
                      sleep(check_interval) unless acquired
              Severity: Minor
              Found in lib/diplomat/lock.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