grokify/ringcentral-sdk-ruby

View on GitHub
lib/ringcentral_sdk/rest/client.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Class has too many lines. [194/150]
Open

    class Client
      ACCESS_TOKEN_TTL  = 600 # 10 minutes
      REFRESH_TOKEN_TTL = 36_000 # 10 hours
      REFRESH_TOKEN_TTL_REMEMBER = 604_800 # 1 week
      ACCOUNT_PREFIX    = '/account/'.freeze
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [28/15]
Open

      def set_token(token)
        if token.is_a? Hash
          token = OAuth2::AccessToken.from_hash(@oauth2client, token)
        end

Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [21/15]
Open

      def send_request(request_sdk = {})
        if request_sdk.is_a? Hash
          request_sdk = RingCentralSdk::REST::Request::Simple.new request_sdk
        elsif !request_sdk.is_a? RingCentralSdk::REST::Request::Base
          raise ArgumentError, 'Request is not a RingCentralSdk::REST::Request::Base'
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Perceived complexity for create_url is too high. [12/7]
Open

      def create_url(url, add_server = false, add_method = nil, add_token = false)
        built_url = ''
        has_http = !url.index('http://').nil? && !url.index('https://').nil?

        built_url += @config.server_url if add_server && !has_http
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method has too many lines. [20/15]
Open

      def create_url(url, add_server = false, add_method = nil, add_token = false)
        built_url = ''
        has_http = !url.index('http://').nil? && !url.index('https://').nil?

        built_url += @config.server_url if add_server && !has_http
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for create_url is too high. [9/6]
Open

      def create_url(url, add_server = false, add_method = nil, add_token = false)
        built_url = ''
        has_http = !url.index('http://').nil? && !url.index('https://').nil?

        built_url += @config.server_url if add_server && !has_http
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.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 send_request is too high. [8/6]
Open

      def send_request(request_sdk = {})
        if request_sdk.is_a? Hash
          request_sdk = RingCentralSdk::REST::Request::Simple.new request_sdk
        elsif !request_sdk.is_a? RingCentralSdk::REST::Request::Base
          raise ArgumentError, 'Request is not a RingCentralSdk::REST::Request::Base'
Severity: Minor
Found in lib/ringcentral_sdk/rest/client.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.

Assignment Branch Condition size for set_token is too high. [31.06/30]
Open

      def set_token(token)
        if token.is_a? Hash
          token = OAuth2::AccessToken.from_hash(@oauth2client, token)
        end

Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method set_token has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def set_token(token)
        if token.is_a? Hash
          token = OAuth2::AccessToken.from_hash(@oauth2client, token)
        end

Severity: Minor
Found in lib/ringcentral_sdk/rest/client.rb - About 1 hr to fix

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

          def create_url(url, add_server = false, add_method = nil, add_token = false)
            built_url = ''
            has_http = !url.index('http://').nil? && !url.index('https://').nil?
    
            built_url += @config.server_url if add_server && !has_http
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/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 set_token has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def set_token(token)
            if token.is_a? Hash
              token = OAuth2::AccessToken.from_hash(@oauth2client, token)
            end
    
    
    Severity: Minor
    Found in lib/ringcentral_sdk/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

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            unless token.is_a? OAuth2::AccessToken
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Useless assignment to variable - req.
    Open

              res = @http.get { |req| req = inflate_request(req, request_sdk) }
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Unused method argument - add_method. If it's necessary, use _ or _add_method as an argument name to indicate that it won't be used.
    Open

          def create_url(url, add_server = false, add_method = nil, add_token = false)
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Convert if nested inside else to elsif.
    Open

              if built_url =~ %r{/$}
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

    Example:

    # bad
    if condition_a
      action_a
    else
      if condition_b
        action_b
      else
        action_c
      end
    end
    
    # good
    if condition_a
      action_a
    elsif condition_b
      action_b
    else
      action_c
    end

    Do not prefix writer method names with set_.
    Open

          def set_token(token)
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Use the return of the conditional for variable assignment and comparison.
    Open

              if built_url =~ %r{/$}
                built_url += url
              else
                built_url += '/' << url
              end
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            unless @config.username.to_s.empty?
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if req_sdk.params.is_a? Hash
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Useless assignment to variable - req.
    Open

              res = @http.delete { |req| req = inflate_request(req, request_sdk) }
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

            ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Use url.index('/').zero? instead of url.index('/') == 0.
    Open

            if url.index('/') == 0
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

    The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

    The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

    Example: EnforcedStyle: predicate (default)

    # bad
    
    foo == 0
    0 > foo
    bar.baz > 0
    
    # good
    
    foo.zero?
    foo.negative?
    bar.baz.positive?

    Example: EnforcedStyle: comparison

    # bad
    
    foo.zero?
    foo.negative?
    bar.baz.positive?
    
    # good
    
    foo == 0
    0 > foo
    bar.baz > 0

    Unused method argument - add_token. If it's necessary, use _ or _add_token as an argument name to indicate that it won't be used.
    Open

          def create_url(url, add_server = false, add_method = nil, add_token = false)
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Useless assignment to variable - req.
    Open

              res = @http.put { |req| req = inflate_request(req, request_sdk) }
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if url.index(URL_PREFIX).nil? && !has_http
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if !ct.nil? && !ct.to_s.strip.empty?
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if token.is_a? Hash
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Avoid using rescue in its modifier form.
    Open

              (RUBY_ENGINE rescue nil || 'ruby'),
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Use the return of the conditional for variable assignment and comparison.
    Open

              if built_url =~ %r{/$}
                built_url += url.gsub(%r{^/+}, '')
              else
                built_url += url
              end
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

            ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if req_sdk.headers.is_a? Hash
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

            ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

              if @config.retry
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Useless assignment to variable - req.
    Open

              res = @http.post { |req| req = inflate_request(req, request_sdk) }
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Do not prefix writer method names with set_.
    Open

          def set_oauth2_client(client = nil)
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Favor format over String#%.
    Open

            ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
    Severity: Minor
    Found in lib/ringcentral_sdk/rest/client.rb by rubocop

    This cop enforces the use of a single string formatting utility. Valid options include Kernel#format, Kernel#sprintf and String#%.

    The detection of String#% cannot be implemented in a reliable manner for all cases, so only two scenarios are considered - if the first argument is a string literal and if the second argument is an array literal.

    Example: EnforcedStyle: format(default)

    # bad
    puts sprintf('%10s', 'hoge')
    puts '%10s' % 'hoge'
    
    # good
    puts format('%10s', 'hoge')

    Example: EnforcedStyle: sprintf

    # bad
    puts format('%10s', 'hoge')
    puts '%10s' % 'hoge'
    
    # good
    puts sprintf('%10s', 'hoge')

    Example: EnforcedStyle: percent

    # bad
    puts format('%10s', 'hoge')
    puts sprintf('%10s', 'hoge')
    
    # good
    puts '%10s' % 'hoge'

    There are no issues that match your filters.

    Category
    Status