grokify/ringcentral-sdk-ruby

View on GitHub

Showing 129 of 129 total issues

Method _subscribe_at_pubnub has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def _subscribe_at_pubnub
        raise 'Subscription is not alive' unless alive?

        s_key = @_subscription['deliveryMode']['subscriberKey']

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

    Consider simplifying this complex logical expression.
    Open

            if
              (s.key?('deliveryMode') && s['deliveryMode']) \
              && (s['deliveryMode'].key?('subscriberKey') && s['deliveryMode']['subscriberKey']) \
              && (
                s['deliveryMode'].key?('address') \
    Severity: Major
    Found in lib/ringcentral_sdk/rest/subscription.rb - About 1 hr to fix

      Method send has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def send(request)
              return @client.request(request) if request.is_a? RingCentralSdk::Helpers::Request
              raise(ArgumentError, 'Request is not a ...Helpers::Request or Hash') unless request.is_a? Hash
      
              verb = request.key?(:verb) ? request[:verb].to_s.downcase : 'get'
      Severity: Minor
      Found in lib/ringcentral_sdk/rest/simple_client.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

      Block has too many lines. [31/25]
      Open

      Gem::Specification.new do |s|
        s.name        = lib
        s.version     = version
        s.date        = '2023-02-20'
        s.summary     = 'RingCentral SDK - Ruby SDK for the RingCentral Connect Platform API'
      Severity: Minor
      Found in ringcentral_sdk.gemspec by rubocop

      This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

            def create(opts)
              req  = RingCentralSdk::REST::Request::Fax.new
              meta = {}
      
              skip = {text: 1, files: 1}
      Severity: Minor
      Found in lib/ringcentral_sdk/rest/messages.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 retrieve has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

              def retrieve(params = {}, retrieve_all = true)
                @last_retrieved = Time.now.to_i
                uri = URI.parse "account/#{@account_id}/extension"
                uri.query = URI.encode_www_form(params) unless params.empty?
                res = @client.http.get do |req|
      Severity: Minor
      Found in lib/ringcentral_sdk/rest/cache/extensions.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 inflate_token has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def inflate_token
              @token = nil unless defined? @token
      
              if (@token.nil? || @token.empty?) && !token_file.nil? && !@token_file.empty?
                @token = IO.read @token_file if File.exist? @token_file
      Severity: Minor
      Found in lib/ringcentral_sdk/rest/configuration.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 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

      Avoid too many return statements within this method.
      Open

              return delete(request) if verb == 'delete'
      Severity: Major
      Found in lib/ringcentral_sdk/rest/simple_client.rb - About 30 mins to fix

        Method inflate_retry_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def inflate_retry_options
                if @retry == false
                  @retry_options = {}
                  return
                end
        Severity: Minor
        Found in lib/ringcentral_sdk/rest/configuration.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def initialize(opts = {})
                  @method = opts[:method]
                  @url = opts[:url]
                  @params = opts[:params]
                  @headers = opts[:headers]
        Severity: Minor
        Found in lib/ringcentral_sdk/rest/request/simple.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

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

                if opts.key? :media
                  if opts[:media].is_a? String
                    req.add_file opts[:media]
                  elsif opts[:media].is_a? Array
                    req.add_files opts[:media]
        Severity: Minor
        Found in lib/ringcentral_sdk/rest/messages.rb and 1 other location - About 15 mins to fix
        lib/ringcentral_sdk/rest/messages.rb on lines 69..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 26.

        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

                if opts.key? :files
                  if opts[:files].is_a? String
                    req.add_file opts[:files]
                  elsif opts[:files].is_a? Array
                    req.add_files opts[:files]
        Severity: Minor
        Found in lib/ringcentral_sdk/rest/messages.rb and 1 other location - About 15 mins to fix
        lib/ringcentral_sdk/rest/messages.rb on lines 32..37

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

        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

        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

                  req = inflate_request req, opts

        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

        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

        Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
        Open

                  to:   opts[:to],

        This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

        By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

        Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

        This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

        Example: EnforcedStyle: specialinsideparentheses (default)

        # The `special_inside_parentheses` style enforces that the first key
        # in a hash literal where the opening brace and the first key are on
        # separate lines is indented one step (two spaces) more than the
        # position inside the opening parentheses.
        
        # bad
        hash = {
          key: :value
        }
        and_in_a_method_call({
          no: :difference
                             })
        
        # good
        special_inside_parentheses
        hash = {
          key: :value
        }
        but_in_a_method_call({
                               its_like: :this
                             })

        Example: EnforcedStyle: consistent

        # The `consistent` style enforces that the first key in a hash
        # literal where the opening brace and the first key are on
        # seprate lines is indented the same as a hash literal which is not
        # defined inside a method call.
        
        # bad
        hash = {
          key: :value
        }
        but_in_a_method_call({
                               its_like: :this
                              })
        
        # good
        hash = {
          key: :value
        }
        and_in_a_method_call({
          no: :difference
        })

        Example: EnforcedStyle: align_braces

        # The `align_brackets` style enforces that the opening and closing
        # braces are indented to the same position.
        
        # bad
        and_now_for_something = {
                                  completely: :different
        }
        
        # good
        and_now_for_something = {
                                  completely: :different
                                }

        Indent the right brace the same as the first position after the preceding left parenthesis.
        Open

                })

        This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

        By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

        Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

        This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

        Example: EnforcedStyle: specialinsideparentheses (default)

        # The `special_inside_parentheses` style enforces that the first key
        # in a hash literal where the opening brace and the first key are on
        # separate lines is indented one step (two spaces) more than the
        # position inside the opening parentheses.
        
        # bad
        hash = {
          key: :value
        }
        and_in_a_method_call({
          no: :difference
                             })
        
        # good
        special_inside_parentheses
        hash = {
          key: :value
        }
        but_in_a_method_call({
                               its_like: :this
                             })

        Example: EnforcedStyle: consistent

        # The `consistent` style enforces that the first key in a hash
        # literal where the opening brace and the first key are on
        # seprate lines is indented the same as a hash literal which is not
        # defined inside a method call.
        
        # bad
        hash = {
          key: :value
        }
        but_in_a_method_call({
                               its_like: :this
                              })
        
        # good
        hash = {
          key: :value
        }
        and_in_a_method_call({
          no: :difference
        })

        Example: EnforcedStyle: align_braces

        # The `align_brackets` style enforces that the opening and closing
        # braces are indented to the same position.
        
        # bad
        and_now_for_something = {
                                  completely: :different
        }
        
        # good
        and_now_for_something = {
                                  completely: :different
                                }

        Final newline missing.
        Open

        gemspec
        Severity: Minor
        Found in Gemfile by rubocop

        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
        Severity
        Category
        Status
        Source
        Language