fog/fog-xenserver

View on GitHub
lib/fog/xenserver/connection.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Cyclomatic complexity for request is too high. [11/6]
Open

      def request(options, *params)
        begin
          parser   = options.delete(:parser)
          method   = options.delete(:method)

Severity: Minor
Found in lib/fog/xenserver/connection.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for authenticate is too high. [7/6]
Open

      def authenticate( username, password )
        response = @factory.call("session.login_with_password", username.to_s, password.to_s)
        unless response["Status"] =~ /Success/
          if response.key?("ErrorDescription") &&
             response["ErrorDescription"].is_a?(Array) &&
Severity: Minor
Found in lib/fog/xenserver/connection.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method request has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def request(options, *params)
        begin
          parser   = options.delete(:parser)
          method   = options.delete(:method)

Severity: Minor
Found in lib/fog/xenserver/connection.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 authenticate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def authenticate( username, password )
        response = @factory.call("session.login_with_password", username.to_s, password.to_s)
        unless response["Status"] =~ /Success/
          if response.key?("ErrorDescription") &&
             response["ErrorDescription"].is_a?(Array) &&
Severity: Minor
Found in lib/fog/xenserver/connection.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

      def initialize(host, port, use_ssl, verify_mode, timeout)
Severity: Minor
Found in lib/fog/xenserver/connection.rb - About 35 mins to fix

    The use of eval is a serious security risk.
    Open

                  response = eval("@factory.call('#{method}', '#{@credentials}', #{params.map {|p|  p.is_a?(String) ? "'#{p}'" : p}.join(',')})")
    Severity: Minor
    Found in lib/fog/xenserver/connection.rb by rubocop

    This cop checks for the use of Kernel#eval and Binding#eval.

    Example:

    # bad
    
    eval(something)
    binding.eval(something)

    Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
    Open

    require 'xmlrpc/client'
    Severity: Minor
    Found in lib/fog/xenserver/connection.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    There are no issues that match your filters.

    Category
    Status