lookitsatravis/api_guardian

View on GitHub

Showing 21 of 21 total issues

Class Configuration has 47 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Configuration
    class Registration
      def add_config_option(key)
        self.class.class_eval { attr_accessor key.to_sym }
      end
Severity: Minor
Found in lib/api_guardian/configuration.rb - About 6 hrs to fix

    Method api_error_handler has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

              def api_error_handler(exception)
                ApiGuardian.logger.error 'ApiError: ' + exception.class.name + ' - ' + exception.message
    
                if exception.is_a? Pundit::NotAuthorizedError
                  user_not_authorized
    Severity: Minor
    Found in lib/api_guardian/concerns/api_errors/handler.rb - About 3 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

    Class ApiController has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class ApiController < ActionController::API
        include ::Pundit
        include ApiGuardian::Concerns::ApiErrors::Handler
        include ApiGuardian::Concerns::ApiRequest::Validator
    
    
    Severity: Minor
    Found in app/controllers/api_guardian/api_controller.rb - About 2 hrs to fix

      Method api_error_handler has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                def api_error_handler(exception)
                  ApiGuardian.logger.error 'ApiError: ' + exception.class.name + ' - ' + exception.message
      
                  if exception.is_a? Pundit::NotAuthorizedError
                    user_not_authorized
      Severity: Major
      Found in lib/api_guardian/concerns/api_errors/handler.rb - About 2 hrs to fix

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

                  def permissions
                    arr = role_permissions_collection.map do |rp|
                      rp.permission.name if rp.granted
                    end.compact
        
        
        Severity: Minor
        Found in lib/api_guardian/concerns/models/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 change has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def change
            create_table :oauth_applications, id: :uuid do |t|
              t.string :name, null: false
              t.string :uid, null: false
              t.string :secret, null: false

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

                def self.complete_reset_password(attributes)
                  instance = new(nil)
                  # Find user by token
                  user = instance.find_by_reset_password_token(attributes[:token])
          
          
          Severity: Minor
          Found in lib/api_guardian/stores/user_store.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 remove_permission has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                    def remove_permission(name, destroy = false)
                      role_permissions.includes(:permission).each do |rp|
                        next unless rp.permission.name == name
                        if destroy
                          rp.destroy
          Severity: Minor
          Found in lib/api_guardian/concerns/models/role.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 authenticate_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  def self.authenticate_request(user, request)
                    return true unless ApiGuardian.configuration.enable_2fa
          
                    if user.otp_enabled
                      otp_header_name = ApiGuardian.configuration.otp_header_name
          Severity: Minor
          Found in lib/api_guardian/strategies/authentication/two_factor.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 validate_content_type has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                    def validate_content_type
                      if request.body.read != ''
                        allowed = determine_content_types
          
                        content_type = request.headers['Content-Type']
          Severity: Minor
          Found in lib/api_guardian/concerns/api_request/validator.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 validate_auth_header has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def validate_auth_header
                  fail StandardError, 'Digits Auth Headers invalid or missing' unless auth_header
                  auth_header.gsub('OAuth ', '').split(', ').each do |piece|
                    key = piece.split('=')[0]
                    next unless key == 'oauth_consumer_key'
          Severity: Minor
          Found in lib/api_guardian/helpers/digits.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 array_permission_check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                    def array_permission_check(actions)
                      grants = []
                      perms = load_permission(actions)
          
                      unless perms.length > 0
          Severity: Minor
          Found in lib/api_guardian/concerns/models/role.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 authenticate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                  def authenticate(auth_hash)
                    # Validate auth data
                    response = get_auth_response auth_hash
                    return nil unless response
          
          
          Severity: Minor
          Found in lib/api_guardian/strategies/authentication/digits.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 render_error has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                    def render_error(status, code, title, detail, exception = nil)
          Severity: Minor
          Found in lib/api_guardian/concerns/api_errors/renderer.rb - About 35 mins to fix

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

                  def password_score(user)
                    password = user.password
            
                    zxcvbn_weak_words = []
            
            
            Severity: Minor
            Found in lib/api_guardian/validators/password_score_validator.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 can? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                      def can?(action)
                        if action.is_a?(Array)
                          if action.length == 1
                            single_permission_check action.first
                          else
            Severity: Minor
            Found in lib/api_guardian/concerns/models/role.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 authenticate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                    def authenticate(access_token)
                      # Get FB user object
                      client = ApiGuardian::Helpers::Facebook.new(access_token)
                      response = client.authorize!
            
            
            Severity: Minor
            Found in lib/api_guardian/strategies/authentication/facebook.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 single_permission_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                      def single_permission_check(action)
                        perm = load_permission(action).first
                        fail ApiGuardian::Errors::InvalidPermissionName, "Permission '#{action}' is not valid." unless perm
            
                        role_permissions_collection.each do |rp|
            Severity: Minor
            Found in lib/api_guardian/concerns/models/role.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_request_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                      def validate_request_type
                        top_params = params.fetch(:data)
                        fail ApiGuardian::Errors::InvalidRequestBody, 'type' unless top_params.fetch(:type, nil)
            
                        expected_request_type = resource_name.pluralize.underscore.dasherize.gsub(/\//, '-').sub(/^-/, '')
            Severity: Minor
            Found in lib/api_guardian/concerns/api_request/validator.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_request_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                      def validate_request_id
                        top_params = params.fetch(:data)
                        fail ApiGuardian::Errors::InvalidRequestBody, 'id' unless top_params.fetch(:id, nil)
            
                        expected_request_id = params[:id]
            Severity: Minor
            Found in lib/api_guardian/concerns/api_request/validator.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