thorin/redmine_ldap_sync

View on GitHub
lib/ldap_sync/entity_manager.rb

Summary

Maintainability
D
2 days
Test Coverage

Method groups_changes has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    def groups_changes(user)
      return unless setting.active?
      changes = { added: SortedSet.new, deleted: SortedSet.new }

      user_groups = user.groups.map {|g| g.name.downcase }
Severity: Minor
Found in lib/ldap_sync/entity_manager.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

File entity_manager.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module LdapSync::EntityManager

  public
    def connect_as_user?; setting.account.include?('$login'); end

Severity: Minor
Found in lib/ldap_sync/entity_manager.rb - About 2 hrs to fix

    Method get_group_closure has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_group_closure(ldap, group, closure=Set.new)
          groupname = group.is_a?(String) ? group : group[n(:groupname)].first
          parent_groups = parents_cache.fetch(groupname) do
            case setting.nested_groups
            when 'on_members'
    Severity: Minor
    Found in lib/ldap_sync/entity_manager.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 groups_changes has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def groups_changes(user)
          return unless setting.active?
          changes = { added: SortedSet.new, deleted: SortedSet.new }
    
          user_groups = user.groups.map {|g| g.name.downcase }
    Severity: Major
    Found in lib/ldap_sync/entity_manager.rb - About 2 hrs to fix

      Method ldap_search has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def ldap_search(ldap, options, &block)
            attrs = options[:attributes]
      
            return ldap.search(options, &block) if attrs.is_a?(Array) || attrs.nil?
      
      
      Severity: Minor
      Found in lib/ldap_sync/entity_manager.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 get_user_fields has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_user_fields(username, user_data=nil, options={})
            fields_to_sync = setting.user_fields_to_sync
            if options.try(:fetch, :include_required, false)
              custom_fields = user_required_custom_fields.map {|cf| cf.id.to_s }
              fields_to_sync -= (User::STANDARD_FIELDS + custom_fields)
      Severity: Minor
      Found in lib/ldap_sync/entity_manager.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 get_group_fields has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_group_fields(groupname, group_data = nil)
            group_data ||= with_ldap_connection do |ldap|
              find_group(ldap, groupname, [n(:groupname), *setting.group_ldap_attrs_to_sync])
            end || {}
      
      
      Severity: Minor
      Found in lib/ldap_sync/entity_manager.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 find_all_dyngroups has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_all_dyngroups(ldap, options = {})
            options = options.reverse_merge(attrs: [n(:groupname), :member], update_cache: false)
            users_base_dn = setting.base_dn.downcase
      
            dyngroups = Hash.new{|h,k| h[k] = []}
      Severity: Minor
      Found in lib/ldap_sync/entity_manager.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 ldap_users has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def ldap_users
            return @ldap_users if defined? @ldap_users
      
            with_ldap_connection do |ldap|
              changes = { enabled: SortedSet.new, locked: SortedSet.new, deleted: SortedSet.new }
      Severity: Minor
      Found in lib/ldap_sync/entity_manager.rb - About 1 hr to fix

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

            def ldap_users
              return @ldap_users if defined? @ldap_users
        
              with_ldap_connection do |ldap|
                changes = { enabled: SortedSet.new, locked: SortedSet.new, deleted: SortedSet.new }
        Severity: Minor
        Found in lib/ldap_sync/entity_manager.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 find_all_groups has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def find_all_groups(ldap, extra_filter, attrs, options = {}, &block)
        Severity: Minor
        Found in lib/ldap_sync/entity_manager.rb - About 35 mins to fix

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

              def find_all_groups(ldap, extra_filter, attrs, options = {}, &block)
                object_class = options[:class] || setting.class_group
                groups_base_dn = setting.has_groups_base_dn? ? setting.groups_base_dn : nil
                group_filter = Net::LDAP::Filter.eq( :objectclass, object_class )
                group_filter &= Net::LDAP::Filter.construct( setting.group_search_filter ) if setting.group_search_filter.present?
          Severity: Minor
          Found in lib/ldap_sync/entity_manager.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

          There are no issues that match your filters.

          Category
          Status