Sorcery/sorcery

View on GitHub

Showing 28 of 28 total issues

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

        def self.included(base)
          base.send(:include, InstanceMethods)

          require 'sorcery/providers/base'
          require 'sorcery/providers/facebook'
Severity: Minor
Found in lib/sorcery/controller/submodules/external.rb - About 1 hr to fix

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

          def authenticate(*credentials, &block)
            raise ArgumentError, 'at least 2 arguments required' if credentials.size < 2
    
            if credentials[0].blank?
              return authentication_response(return_value: false, failure: :invalid_login, &block)
    Severity: Minor
    Found in lib/sorcery/model.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 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def self.included(base)
              base.sorcery_config.class_eval do
                # The attribute name to hold activation state (active/pending).
                attr_accessor :activation_state_attribute_name
                # The attribute name to hold activation code (sent by email).
    Severity: Minor
    Found in lib/sorcery/model/submodules/user_activation.rb - About 1 hr to fix

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

              def self.included(base)
                base.sorcery_config.class_eval do
                  # Reset password code attribute name.
                  attr_accessor :reset_password_token_attribute_name
                  # Expires at attribute name.
      Severity: Minor
      Found in lib/sorcery/model/submodules/reset_password.rb - About 1 hr to fix

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

                  def user_attrs(user_info_mapping, user_hash)
                    attrs = {}
                    user_info_mapping.each do |k, v|
                      if (varr = v.split('/')).size > 1
                        attribute_value = begin
        Severity: Minor
        Found in lib/sorcery/controller/submodules/external.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 copy_migration_files has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def copy_migration_files
                # Copy core migration file in all cases except when you pass --only-submodules.
                return unless defined?(ActiveRecord)
        
                migration_template 'migration/core.rb', 'db/migrate/sorcery_core.rb', migration_class_name: migration_class_name unless only_submodules?
        Severity: Minor
        Found in lib/generators/sorcery/install_generator.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

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

                module ClassMethods
                  # Find user by token, also checks for expiration.
                  # Returns the user if token found and is valid.
                  def load_from_reset_password_token(token, &block)
                    load_from_token(
        Severity: Minor
        Found in lib/sorcery/model/submodules/reset_password.rb and 1 other location - About 55 mins to fix
        lib/sorcery/model/submodules/magic_login.rb on lines 52..76

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

        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

                module ClassMethods
                  # Find user by token, also checks for expiration.
                  # Returns the user if token found and is valid.
                  def load_from_magic_login_token(token, &block)
                    load_from_token(
        Severity: Minor
        Found in lib/sorcery/model/submodules/magic_login.rb and 1 other location - About 55 mins to fix
        lib/sorcery/model/submodules/reset_password.rb on lines 59..83

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

        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

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

                  def validate_session
                    session_to_use = Config.session_timeout_from_last_action ? session[:last_action_time] : session[:login_time]
                    if (session_to_use && sorcery_session_expired?(session_to_use.to_time)) || sorcery_session_invalidated?
                      reset_sorcery_session
                      remove_instance_variable :@current_user if defined? @current_user
        Severity: Minor
        Found in lib/sorcery/controller/submodules/session_timeout.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 login has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def login(*credentials)
                @current_user = nil
        
                user_class.authenticate(*credentials) do |user, failure_reason|
                  if failure_reason
        Severity: Minor
        Found in lib/sorcery/controller.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 realm_name_by_controller has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                  def realm_name_by_controller
                    if defined?(ActionController::Base)
                      current_controller = self.class
                      while current_controller != ActionController::Base
                        result = Config.controller_to_realm_map[current_controller.controller_name]
        Severity: Minor
        Found in lib/sorcery/controller/submodules/http_basic_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

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

              def get_user_hash(access_token)
                response = access_token.get(user_info_path)
                body = JSON.parse(response.body)
                auth_hash(access_token).tap do |h|
                  h[:user_info] = body
        Severity: Minor
        Found in lib/sorcery/providers/battlenet.rb and 1 other location - About 30 mins to fix
        lib/sorcery/providers/paypal.rb on lines 25..31

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

        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

              def get_user_hash(access_token)
                response = access_token.get(user_info_url)
                body = JSON.parse(response.body)
                auth_hash(access_token).tap do |h|
                  h[:user_info] = body
        Severity: Minor
        Found in lib/sorcery/providers/paypal.rb and 1 other location - About 30 mins to fix
        lib/sorcery/providers/battlenet.rb on lines 21..27

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

        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

        Avoid too many return statements within this method.
        Open

                  return authentication_response(user: user, failure: :invalid_password, &block)
        Severity: Major
        Found in lib/sorcery/model.rb - About 30 mins to fix

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

                    def generate_magic_login_token!
                      config = sorcery_config
                      attributes = {
                        config.magic_login_token_attribute_name => TemporaryToken.generate_random_token,
                        config.magic_login_email_sent_at_attribute_name => Time.now.in_time_zone
          Severity: Minor
          Found in lib/sorcery/model/submodules/magic_login.rb and 1 other location - About 25 mins to fix
          lib/sorcery/model/submodules/reset_password.rb on lines 89..95

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

          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

                    def generate_reset_password_token!
                      config = sorcery_config
                      attributes = { config.reset_password_token_attribute_name => TemporaryToken.generate_random_token,
                                     config.reset_password_email_sent_at_attribute_name => Time.now.in_time_zone }
                      attributes[config.reset_password_token_expires_at_attribute_name] = Time.now.in_time_zone + config.reset_password_expiration_period if config.reset_password_expiration_period
          Severity: Minor
          Found in lib/sorcery/model/submodules/reset_password.rb and 1 other location - About 25 mins to fix
          lib/sorcery/model/submodules/magic_login.rb on lines 82..90

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

          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

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

                    def prevent_locked_user_login
                      config = sorcery_config
                      if !login_unlocked? && config.login_lock_time_period != 0
                        login_unlock! if send(config.lock_expires_at_attribute_name) <= Time.now.in_time_zone
                      end
          Severity: Minor
          Found in lib/sorcery/model/submodules/brute_force_protection.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 find_by_credentials has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def find_by_credentials(credentials)
                    relation = nil
          
                    @klass.sorcery_config.username_attribute_names.each do |attribute|
                      if @klass.sorcery_config.downcase_username_before_authenticating
          Severity: Minor
          Found in lib/sorcery/adapters/active_record_adapter.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 sorcery_session_invalidated? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                    def sorcery_session_invalidated?
                      return false unless Config.session_timeout_invalidate_active_sessions_enabled
                      return false unless current_user.present? && current_user.try(:invalidate_sessions_before).present?
          
                      time = session[:login_time] || session[:last_action_time] || Time.now.in_time_zone
          Severity: Minor
          Found in lib/sorcery/controller/submodules/session_timeout.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

          Identical blocks of code found in 3 locations. Consider refactoring.
          Open

                def process_callback(params, session)
                  args = {
                    oauth_verifier:       params[:oauth_verifier],
                    request_token:        session[:request_token],
                    request_token_secret: session[:request_token_secret]
          Severity: Minor
          Found in lib/sorcery/providers/twitter.rb and 2 other locations - About 20 mins to fix
          lib/sorcery/providers/jira.rb on lines 60..68
          lib/sorcery/providers/xing.rb on lines 49..57

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

          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

          Severity
          Category
          Status
          Source
          Language