mcordell/grape_token_auth

View on GitHub

Showing 13 of 15 total issues

Method included has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def self.included(base)
      base.helpers do
        def throw_unauthorized(message)
          throw(:warden, errors: message)
        end
Severity: Minor
Found in lib/grape_token_auth/apis/password_api.rb - About 5 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 included has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.included(base)
      base.helpers do
        def throw_unauthorized(message)
          throw(:warden, errors: message)
        end
Severity: Major
Found in lib/grape_token_auth/apis/password_api.rb - About 3 hrs to fix

    Method included has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.included(base)
          base.helpers do
            def auth_hash
              @auth_hash ||= begin
                hash = request.env['rack.session'].delete('gta.omniauth.auth')
    Severity: Major
    Found in lib/grape_token_auth/apis/omniauth_api.rb - About 2 hrs to fix

      Method included has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def self.included(base)
              base.serialize :tokens, JSON
              base.after_initialize { self.tokens ||= {} }
              base.validates :password, presence: true, on: :create
              base.validate :password_confirmation_matches,
      Severity: Major
      Found in lib/grape_token_auth/orm_integrations/active_record_token_auth.rb - About 2 hrs to fix

        Method included has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.included(base)
              base.helpers do
                def find_resource(data, mapping)
                  token_authorizer = TokenAuthorizer.new(data)
                  token_authorizer.find_resource(mapping)
        Severity: Minor
        Found in lib/grape_token_auth/apis/session_api.rb - About 1 hr to fix

          Method included has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.included(base)
                base.helpers do
                  def find_resource(data, mapping)
                    token_authorizer = TokenAuthorizer.new(data)
                    token_authorizer.find_resource(mapping)
          Severity: Minor
          Found in lib/grape_token_auth/apis/session_api.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 included has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.included(base)
                base.helpers do
                  def auth_hash
                    @auth_hash ||= begin
                      hash = request.env['rack.session'].delete('gta.omniauth.auth')
          Severity: Minor
          Found in lib/grape_token_auth/apis/omniauth_api.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 token_is_current? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def token_is_current?(token, client_id)
                  client_id_info = tokens[client_id]
                  expiry     = client_id_info['expiry'] || client_id_info[:expiry]
                  token_hash = client_id_info['token'] || client_id_info[:token]
                  return false unless expiry && token
          Severity: Minor
          Found in lib/grape_token_auth/orm_integrations/active_record_token_auth.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def initialize(uid = nil, client_id = nil, token = nil,
                             expiry = nil, warden = nil)
          Severity: Minor
          Found in lib/grape_token_auth/authorizer_data.rb - About 35 mins to fix

            Method token_can_be_reused? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def token_can_be_reused?(token, client_id)
                    updated_at = fetch_with_indifference(tokens[client_id], :updated_at)
                    last_token = fetch_with_indifference(tokens[client_id], :last_token)
                    return false unless updated_at && last_token
                    return false unless within_batch_window?(Time.parse(updated_at))
            Severity: Minor
            Found in lib/grape_token_auth/orm_integrations/active_record_token_auth.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 whitelisted_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def whitelisted_params
                  whitelist = GrapeTokenAuth.configuration.param_white_list
                  return unless whitelist
                  scoped_list = whitelist[scope] || whitelist[scope.to_s]
                  return unless scoped_list
            Severity: Minor
            Found in lib/grape_token_auth/omniauth/omniauth_resource.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 find_resource has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def find_resource(scope)
                  initialize_resource_class(scope)
                  return nil unless resource_class
            
                  return nil unless data.token_prerequisites_present?
            Severity: Minor
            Found in lib/grape_token_auth/token_authorizer.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 validate_redirect_url! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                    def validate_redirect_url!(url)
                      white_list = GrapeTokenAuth.configuration.redirect_whitelist
                      return unless white_list
                      url_valid = white_list.include?(url)
                      error!({ errors: 'redirect url is not in whitelist', status: 'error' }, 403) unless url_valid
            Severity: Minor
            Found in lib/grape_token_auth/apis/password_api.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