SysMO-DB/seek

View on GitHub
app/models/policy.rb

Summary

Maintainability
F
3 days
Test Coverage

File policy.rb has 400 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Policy < ActiveRecord::Base
  
  has_many :permissions,
           :dependent => :destroy,
           :order => "created_at ASC",
Severity: Minor
Found in app/models/policy.rb - About 5 hrs to fix

    Method set_attributes_with_sharing has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

      def set_attributes_with_sharing sharing, projects
        # if no data about sharing is given, it should be some user (not the owner!)
        # who is editing the asset - no need to do anything with policy / permissions: return success
        self.tap do |policy|
          if sharing
    Severity: Minor
    Found in app/models/policy.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

    Class Policy has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Policy < ActiveRecord::Base
      
      has_many :permissions,
               :dependent => :destroy,
               :order => "created_at ASC",
    Severity: Minor
    Found in app/models/policy.rb - About 4 hrs to fix

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

        def permissions_to_people_group permissions, people_in_group
            permissions.each do |permission|
              contributor_id = permission.contributor_id
              access_type = permission.access_type
              case permission.contributor_type
      Severity: Minor
      Found in app/models/policy.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 policy_to_people_group has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def policy_to_people_group people_in_group, contributor=User.current_user.person
            if sharing_scope == Policy::ALL_SYSMO_USERS
               people_in_network = get_people_in_network access_type
               people_in_group['Network'] |= people_in_network unless people_in_network.blank?
            elsif sharing_scope == Policy::EVERYONE
      Severity: Minor
      Found in app/models/policy.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 concat_roles_to_name has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def concat_roles_to_name grouped_people_by_access_type, creators, asset_managers
          creator_id_array = creators.collect{|c| c.id unless c.blank?}
          asset_manage_id_array = asset_managers.collect{|am| am.id unless am.blank?}
           grouped_people_by_access_type = grouped_people_by_access_type.reject{|key,value| key == Policy::DETERMINED_BY_GROUP}.each_value do |value|
             value.each do |person|
      Severity: Minor
      Found in app/models/policy.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 set_attributes_with_sharing has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def set_attributes_with_sharing sharing, projects
          # if no data about sharing is given, it should be some user (not the owner!)
          # who is editing the asset - no need to do anything with policy / permissions: return success
          self.tap do |policy|
            if sharing
      Severity: Minor
      Found in app/models/policy.rb - About 1 hr to fix

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

          def summarize_permissions creators=[User.current_user.try(:person)], asset_managers = [], contributor=User.current_user.try(:person)
                #build the hash containing contributor_type as key and the people in these groups as value,exception:'Public' holds the access_type as the value
                people_in_group = {'Person' => [], 'FavouriteGroup' => [], 'WorkGroup' => [], 'Project' => [], 'Institution' => [], 'WhiteList' => [], 'BlackList' => [],'Network' => [], 'Public' => 0}
                #the result return: a hash contain the access_type as key, and array of people as value
                grouped_people_by_access_type = {}
        Severity: Minor
        Found in app/models/policy.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 summarize_permissions has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def summarize_permissions creators=[User.current_user.try(:person)], asset_managers = [], contributor=User.current_user.try(:person)
                #build the hash containing contributor_type as key and the people in these groups as value,exception:'Public' holds the access_type as the value
                people_in_group = {'Person' => [], 'FavouriteGroup' => [], 'WorkGroup' => [], 'Project' => [], 'Institution' => [], 'WhiteList' => [], 'BlackList' => [],'Network' => [], 'Public' => 0}
                #the result return: a hash contain the access_type as key, and array of people as value
                grouped_people_by_access_type = {}
        Severity: Minor
        Found in app/models/policy.rb - About 1 hr to fix

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

            def self.get_access_type_wording(access_type, downloadable=false)
              #MERGENOTE - VLN used hard-coded values here that should be moved into the en.yml file
              case access_type
                when Policy::DETERMINED_BY_GROUP
                  return I18n.t('access.determined_by_group')
          Severity: Minor
          Found in app/models/policy.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_people_in_FG has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_people_in_FG contributor, fg_id=nil, is_white_list=nil, is_black_list=nil
              if is_white_list
                f_group = FavouriteGroup.where(["name = ? AND user_id = ?", "__whitelist__", contributor.user.id]).first
              elsif is_black_list
                f_group = FavouriteGroup.where(["name = ? AND user_id = ?", "__blacklist__", contributor.user.id]).first
          Severity: Minor
          Found in app/models/policy.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 get_people_in_network has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_people_in_network access_type
              people_in_network = [] #id, name, access_type
              projects = Project.all
              projects.each do |project|
                project.people.each do |person|
          Severity: Minor
          Found in app/models/policy.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 is_entirely_private? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def is_entirely_private? grouped_people_by_access_type, contributor
              entirely_private = true
              if access_type > Policy::NO_ACCESS
                  entirely_private = false
              else
          Severity: Minor
          Found in app/models/policy.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 I18n.t('access.managing')
          Severity: Major
          Found in app/models/policy.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return "Invalid access type"
            Severity: Major
            Found in app/models/policy.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return downloadable ? I18n.t('access.editing_downloadable') : I18n.t('access.editing')
              Severity: Major
              Found in app/models/policy.rb - About 30 mins to fix

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

                  def precedence array1, array2
                    result = []
                    result |= array2
                     array1.each do |a1|
                       check = false
                Severity: Minor
                Found in app/models/policy.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

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

                  def get_people_in_institution institution_id, access_type
                      institution = Institution.find(institution_id)
                    if institution
                      people_in_institution = [] #id, name, access_type
                      institution.people.each do |person|
                Severity: Minor
                Found in app/models/policy.rb and 1 other location - About 25 mins to fix
                app/models/policy.rb on lines 438..445

                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 get_people_in_project project_id, access_type
                      project = Project.find(project_id)
                    if project
                      people_in_project = [] #id, name, access_type
                      project.people.each do |person|
                Severity: Minor
                Found in app/models/policy.rb and 1 other location - About 25 mins to fix
                app/models/policy.rb on lines 450..457

                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

                There are no issues that match your filters.

                Category
                Status