thorin/redmine_ldap_sync

View on GitHub
lib/ldap_sync/infectors/auth_source_ldap.rb

Summary

Maintainability
F
3 days
Test Coverage

File auth_source_ldap.rb has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module LdapSync::Infectors::AuthSourceLdap

  module InstanceMethods
    include LdapSync::EntityManager

Severity: Minor
Found in lib/ldap_sync/infectors/auth_source_ldap.rb - About 4 hrs to fix

    Method sync_users has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def sync_users
          if connect_as_user?
            trace "   -> Cannot synchronize: no account/password configured"; return
          end
          unless setting.active?
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.rb - About 4 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 trace has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

          def trace(msg = nil, options = {}, &block)
            return if trace_level == :silent || msg.nil?
            if !running_rake?
              logger.error(block_given? ? yield : msg) if options[:level] == :error
              return
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.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

    Method sync_user has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def sync_user(user, is_new_user = false, options = {})
          with_ldap_connection(options[:login], options[:password]) do |ldap|
            trace "-- #{is_new_user ? 'Creating' : 'Updating'} user '#{user.login}' (#{user.name})...",
              :level => is_new_user ? :change : :debug,
              :obj => user.login
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.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

    Method sync_user_status has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

          def sync_user_status(user, flags, locked)
            locked ||= flags && flags != :deleted && account_locked?(flags)
            deleted = flags == :deleted
    
            message = if user.active?
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.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

    Method trace_groups_changes_summary has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

          def trace_groups_changes_summary(user, groups, added, deleted)
            return unless running_rake?
    
            a = added.size; d = deleted.size; nc = groups[:added].size - a
            added_names = added.map {|g| g.lastname.mb_chars.downcase.to_s }
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.rb - About 2 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 sync_users has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def sync_users
          if connect_as_user?
            trace "   -> Cannot synchronize: no account/password configured"; return
          end
          unless setting.active?
    Severity: Minor
    Found in lib/ldap_sync/infectors/auth_source_ldap.rb - About 1 hr to fix

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

          def sync_groups
            if connect_as_user?
              trace "   -> Cannot synchronize: no account/password configured"; return
            end
            unless setting.active?
      Severity: Minor
      Found in lib/ldap_sync/infectors/auth_source_ldap.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 sync_user_groups has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def sync_user_groups(user)
              return unless setting.active?
      
              if setting.has_fixed_group? && !user.member_of_group?(setting.fixed_group)
                user.add_to_fixed_group
      Severity: Minor
      Found in lib/ldap_sync/infectors/auth_source_ldap.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 sync_user_status has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def sync_user_status(user, flags, locked)
              locked ||= flags && flags != :deleted && account_locked?(flags)
              deleted = flags == :deleted
      
              message = if user.active?
      Severity: Minor
      Found in lib/ldap_sync/infectors/auth_source_ldap.rb - About 1 hr to fix

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

              def find_or_create_user(username)
                user, is_invalid = find_local_user(username)
                return nil, false if is_invalid
                return user unless user.nil? && setting.create_users?
        
        
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.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 create_and_sync_group has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def create_and_sync_group(group_data, attr_groupname)
                groupname = group_data[attr_groupname].first
                return unless setting.groupname_regexp =~ groupname
        
                group, is_new_group = find_or_create_group(groupname, group_data)
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.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 sync_user_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def sync_user_fields(user, user_data = nil)
                return unless setting.active? && setting.sync_user_fields?
        
                user.synced_fields = get_user_fields(user.login, user_data)
        
        
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.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 sync_admin_privilege has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def sync_admin_privilege(user)
                return unless setting.has_admin_group?
        
                if user.member_of_group?(setting.admin_group)
                  unless user.admin?
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.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

                  if user.try(:active?)
                    if user.archive!
                      change user.login, "-- Archived active user '#{user.login}' (#{user.name})"
                    else
                      change user.login, "-- Failed to archive active user '#{user.login}'"
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.rb and 1 other location - About 35 mins to fix
        lib/ldap_sync/infectors/auth_source_ldap.rb on lines 67..75

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

        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 user.try(:active?)
                    if user.lock!
                      change user.login, "-- Locked active user '#{user.login}' (#{user.name})"
                    else
                      change user.login, "-- Failed to lock active user '#{user.login}'"
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.rb and 1 other location - About 35 mins to fix
        lib/ldap_sync/infectors/auth_source_ldap.rb on lines 83..91

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

        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

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

                  error_message = if user.email_is_taken
                    mail_owner = User.find_by_mail(user.mail)
                    fmt = User.name_formatter[:firstname_lastname]
                    "email already taken by #{mail_owner.name(fmt)} (#{mail_owner.login})"
                  else
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.rb and 1 other location - About 30 mins to fix
        lib/ldap_sync/infectors/auth_source_ldap.rb on lines 294..299

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

        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

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

                  error_message = if user.email_is_taken
                    mail_owner = User.find_by_mail(user.mail)
                    fmt = User.name_formatter[:firstname_lastname]
                    "email already taken by #{mail_owner.name(fmt)} (#{mail_owner.login})"
                  else
        Severity: Minor
        Found in lib/ldap_sync/infectors/auth_source_ldap.rb and 1 other location - About 30 mins to fix
        lib/ldap_sync/infectors/auth_source_ldap.rb on lines 185..190

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

        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

        There are no issues that match your filters.

        Category
        Status