rubykube/barong

View on GitHub

Showing 15 of 65 total issues

File users.rb has 542 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module API
  module V2
    module Admin
      # Admin functionality over users table
      class Users < Grape::API
Severity: Major
Found in app/api/v2/admin/users.rb - About 5 hrs to fix

    Class Authorize has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Authorize
        STATE_CHANGING_VERBS = %w[POST PUT PATCH DELETE TRACE].freeze
        # Custom Error class to support error status and message
        class AuthError < StandardError
          attr_reader :code
    Severity: Minor
    Found in lib/barong/authorize.rb - About 2 hrs to fix

      Method handle_message has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def handle_message(delivery_info, _metadata, payload)
          exchange    = @exchanges.select { |_, ex| ex[:name] == delivery_info[:exchange] }
          exchange_id = exchange.keys.first.to_s
          signer      = exchange[exchange_id.to_sym][:signer]
      
      
      Severity: Minor
      Found in app/services/event_mailer.rb - About 1 hr to fix

        Method authorize has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
        Open

          def authorize
            @restrictions = Rails.cache.fetch('restrictions', expires_in: 5.minutes) { fetch_restrictions }
        
            # whitelink path
            unless params[:path] == 'api/v2/barong/identity/users/access'
        Severity: Minor
        Found in app/controllers/authorize_controller.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 seed_users has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
        Open

            def seed_users
              logger.info "Seeding users"
              seeds["users"].each do |seed|
                logger.info "---"
        
        
        Severity: Minor
        Found in lib/barong/seed.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 perform has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def perform(user_id, identificator)
                # user, that will be verified
                @user = User.find(user_id)
                # exact batch of the docs to be verified
                docs = @user.documents.where(identificator: identificator)
        Severity: Minor
        Found in app/workers/kyc/kycaid/document_worker.rb - About 1 hr to fix

          Method perform has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
          Open

                def perform(params)
                  params = params.symbolize_keys
                  params.slice(:verification_id, :applicant_id, :verified, :verifications)
          
                  user = Profile.find_by(applicant_id: params[:applicant_id]).user
          Severity: Minor
          Found in app/workers/kyc/kycaid/verifications_worker.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

          Consider simplifying this complex logical expression.
          Open

              return false if (operator == :and && res.all?) || (operator == :or && res.any?) ||
                              (operator == :not && !res.all?)
          Severity: Major
          Found in app/services/event_mailer.rb - About 40 mins to fix

            Method seed_restrictions has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
            Open

                def seed_restrictions
                  logger.info "Seeding restrictions"
                  return logger.info "Restrictions seed is empty!" if seeds["restrictions"].empty?
                  
                  seeds["restrictions"].each do |seed|
            Severity: Minor
            Found in lib/barong/seed.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 validate_permissions! has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
            Open

                def validate_permissions!(user)
                  # Caches Permission.all result to optimize
                  permissions = Rails.cache.fetch('permissions', expires_in: 5.minutes) { Permission.all.to_ary }
            
                  permissions.select! { |a| a.role == user.role && ( a.verb == @request.env['REQUEST_METHOD'] || a.verb == 'ALL' ) && @path.starts_with?(a.path) }
            Severity: Minor
            Found in lib/barong/authorize.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 handle_message has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
            Open

              def handle_message(delivery_info, _metadata, payload)
                exchange    = @exchanges.select { |_, ex| ex[:name] == delivery_info[:exchange] }
                exchange_id = exchange.keys.first.to_s
                signer      = exchange[exchange_id.to_sym][:signer]
            
            
            Severity: Minor
            Found in app/services/event_mailer.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 Rails.root.join(value).tap { |p| path!(key, p) }
            Severity: Major
            Found in lib/barong/app.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  if restriction = @restrictions[category]['country']&.find { |r| r[0]&.casecmp?(country) }                   then return restriction end
              Severity: Major
              Found in app/controllers/authorize_controller.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                          return Regexp.new value
                Severity: Major
                Found in lib/barong/app.rb - About 30 mins to fix

                  Method api_key_owner has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
                  Open

                      def api_key_owner
                        api_key = APIKeysVerifier.new(api_key_params)
                  
                        # validate that nonce is a positive integer
                        error!({ errors: ['authz.nonce_not_valid_timestamp'] }, 401) if api_key_params[:nonce].to_i <= 0
                  Severity: Minor
                  Found in lib/barong/authorize.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