cyberark/conjur-api-ruby

View on GitHub

Showing 123 of 126 total issues

Class API has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

  class API
    # Router translates method arguments to rest-ful API request parameters.
    # because of this, most of the methods suffer from :reek:LongParameterList:
    # and :reek:UtilityFunction:
    module Router
Severity: Minor
Found in lib/conjur/api/router.rb - About 4 hrs to fix

    Method add_option has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

          def add_option name, options = {}, &def_proc
            accepted_options << name
            allow_env = options[:env].nil? || options[:env]
            env_var = options[:env] || "CONJUR_#{name.to_s.upcase}"
            def_val = options[:default]
    Severity: Minor
    Found in lib/conjur/configuration.rb - About 2 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

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

        def memberships options = {}
          request = if options.delete(:recursive) == false
            options["memberships"] = true
          else
            options["all"] = true
    Severity: Minor
    Found in lib/conjur/acts_as_role.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 add_option has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def add_option name, options = {}, &def_proc
            accepted_options << name
            allow_env = options[:env].nil? || options[:env]
            env_var = options[:env] || "CONJUR_#{name.to_s.upcase}"
            def_val = options[:default]
    Severity: Minor
    Found in lib/conjur/configuration.rb - About 1 hr to fix

      Method prefixlen has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def prefixlen
            unless @prefixlen
              return @prefixlen = 0 if (mask = mask_addr) == 0
      
              @prefixlen = ipv4? ? 32 : 128
      Severity: Minor
      Found in lib/conjur/cidr.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 create_log has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.create_log param
          if param
            if param.is_a? String
              if param == 'stdout'
                Logger.new $stdout
      Severity: Minor
      Found in lib/conjur/log.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

      Conjur::CIDR#prefixlen has approx 7 statements
      Open

          def prefixlen
      Severity: Minor
      Found in lib/conjur/cidr.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      Conjur::API#authenticator_authenticate_get has 4 parameters
      Open

            def authenticator_authenticate_get authenticator, service_id, account: Conjur.configuration.account, options: {}
      Severity: Minor
      Found in lib/conjur/api/authn.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::API#new_from_key has 4 parameters
      Open

            def new_from_key username, api_key, account: Conjur.configuration.account, remote_ip: nil
      Severity: Minor
      Found in lib/conjur/base.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::API#authenticate_local has approx 8 statements
      Open

            def authenticate_local username, account: Conjur.configuration.account, expiration: nil, cidr: nil
      Severity: Minor
      Found in lib/conjur/api/authn.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      Conjur::API#init_from_authn_local has 5 parameters
      Open

          def init_from_authn_local username, account: Conjur.configuration.account, remote_ip: nil, expiration: nil, cidr: nil
      Severity: Minor
      Found in lib/conjur/base.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::Escape::ClassMethods#path_or_query_escape refers to 'str' more than self (maybe move it to another class?)
      Open

              str = str.id if str.respond_to?(:id)
              # Leave colons and forward slashes alone
              require 'addressable/uri'
              Addressable::URI.encode(str.to_s)
      Severity: Minor
      Found in lib/conjur/escape.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Conjur::HasAttributes#annotation_value is controlled by argument 'name'
      Open

              (annotations.find{|a| a['name'] == name} || {})['value']
      Severity: Minor
      Found in lib/conjur/has_attributes.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      Conjur::API#host_factory_create_host has approx 6 statements
      Open

            def host_factory_create_host token, id, options = {}
      Severity: Minor
      Found in lib/conjur/api/host_factories.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      Conjur::API#load_policy has 4 parameters
      Open

          def load_policy id, policy, account: Conjur.configuration.account, method: POLICY_METHOD_POST
      Severity: Minor
      Found in lib/conjur/api/policies.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::API#resources has approx 12 statements
      Open

          def resources options = {}
      Severity: Minor
      Found in lib/conjur/api/resources.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      Conjur::API#authenticate_local has 4 parameters
      Open

            def authenticate_local username, account: Conjur.configuration.account, expiration: nil, cidr: nil
      Severity: Minor
      Found in lib/conjur/api/authn.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::API#init_from_key has 4 parameters
      Open

          def init_from_key username, api_key, account: Conjur.configuration.account, remote_ip: nil
      Severity: Minor
      Found in lib/conjur/base.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Conjur::Configuration#add_option has approx 26 statements
      Open

            def add_option name, options = {}, &def_proc
      Severity: Minor
      Found in lib/conjur/configuration.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      Conjur::API#update_password has 4 parameters
      Open

            def update_password username, password, new_password, account: Conjur.configuration.account
      Severity: Minor
      Found in lib/conjur/api/authn.rb by reek

      A Long Parameter List occurs when a method has a lot of parameters.

      Example

      Given

      class Dummy
        def long_list(foo,bar,baz,fling,flung)
          puts foo,bar,baz,fling,flung
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [2]:Dummy#long_list has 5 parameters (LongParameterList)

      A common solution to this problem would be the introduction of parameter objects.

      Severity
      Category
      Status
      Source
      Language