openSUSE/open-build-service

View on GitHub
src/api/app/models/project.rb

Summary

Maintainability
F
5 days
Test Coverage
A
90%

Class Project has 122 methods (exceeds 20 allowed). Consider refactoring.
Open

class Project < ApplicationRecord
  include FlagHelper
  include FlagValidations
  include CanRenderModel
  include HasRelationships
Severity: Major
Found in src/api/app/models/project.rb - About 2 days to fix

    Method branch_local_repositories has a Cognitive Complexity of 45 (exceeds 8 allowed). Consider refactoring.
    Open

      def branch_local_repositories(project, pkg_to_enable, opts = {})
        # shall we use the repositories from a different project?
        project = project.update_instance_or_self('OBS', 'BranchRepositoriesFromProject')
        skip_repos = []
        a = project.find_attribute('OBS', 'BranchSkipRepositories')
    Severity: Minor
    Found in src/api/app/models/project.rb - About 6 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_repository_pathes has a Cognitive Complexity of 38 (exceeds 8 allowed). Consider refactoring.
    Open

      def sync_repository_pathes
        # check all my repositories and ..
        repositories.each do |repo|
          cycle_detection = {}
          repo.path_elements.each do |path|
    Severity: Minor
    Found in src/api/app/models/project.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

    Method revoke_requests has a Cognitive Complexity of 23 (exceeds 8 allowed). Consider refactoring.
    Open

      def revoke_requests
        # Find open requests involving self and:
        # - revoke them if self is source
        # - decline if self is target
        # Note: As requests are a backend matter, it's pointless to include them into the transaction below
    Severity: Minor
    Found in src/api/app/models/project.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 remove_repositories has a Cognitive Complexity of 17 (exceeds 8 allowed). Consider refactoring.
    Open

        def remove_repositories(repositories, opts = {})
          deleted_repository = Repository.deleted_instance
    
          repositories.each do |repo|
            linking_repositories = repo.linking_repositories
    Severity: Minor
    Found in src/api/app/models/project.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 branch_local_repositories has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def branch_local_repositories(project, pkg_to_enable, opts = {})
        # shall we use the repositories from a different project?
        project = project.update_instance_or_self('OBS', 'BranchRepositoriesFromProject')
        skip_repos = []
        a = project.find_attribute('OBS', 'BranchSkipRepositories')
    Severity: Minor
    Found in src/api/app/models/project.rb - About 1 hr to fix

      Method branch_copy_flags has a Cognitive Complexity of 15 (exceeds 8 allowed). Consider refactoring.
      Open

        def branch_copy_flags(project)
          # Copy the flags from the other project, adjusting them appropriately
          # for this one being a branch of it:
          #
          # - enable building
      Severity: Minor
      Found in src/api/app/models/project.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 write_to_backend has a Cognitive Complexity of 14 (exceeds 8 allowed). Consider refactoring.
      Open

        def write_to_backend
          # expire cache
          reset_cache
      
          raise ArgumentError, 'no commit_user set' unless @commit_opts[:no_backend_write] || @commit_opts[:login] || @commit_user
      Severity: Minor
      Found in src/api/app/models/project.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_repository_pathes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

        def sync_repository_pathes
          # check all my repositories and ..
          repositories.each do |repo|
            cycle_detection = {}
            repo.path_elements.each do |path|
      Severity: Minor
      Found in src/api/app/models/project.rb - About 1 hr to fix

        Method branch_remote_repositories has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def branch_remote_repositories(project)
            remote_project = Project.new(name: project)
            remote_project_meta = Nokogiri::XML(remote_project.meta.content, &:strict)
            local_project_meta = Nokogiri::XML(render_xml, &:strict)
        
        
        Severity: Minor
        Found in src/api/app/models/project.rb - About 1 hr to fix

          Method validate_repository_xml_attribute has a Cognitive Complexity of 12 (exceeds 8 allowed). Consider refactoring.
          Open

              def validate_repository_xml_attribute(request_data, project_name)
                # Check used repo pathes for existence and read access permissions
                request_data.elements('repository') do |repository|
                  repository.elements('path') do |element|
                    # permissions check
          Severity: Minor
          Found in src/api/app/models/project.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 can_be_unlocked? has a Cognitive Complexity of 11 (exceeds 8 allowed). Consider refactoring.
          Open

            def can_be_unlocked?(with_exception = true)
              if is_maintenance_incident?
                requests = BsRequest.where(state: %i[new review declined]).joins(:bs_request_actions)
                maintenance_release_requests = requests.where(bs_request_actions: { type: 'maintenance_release', source_project: name })
                if maintenance_release_requests.exists?
          Severity: Minor
          Found in src/api/app/models/project.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_by_name has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
          Open

              def get_by_name(name, include_all_packages: false)
                dbp = find_by_name(name, skip_check_access: true)
                if dbp.nil?
                  dbp, remote_name = find_remote_project(name)
                  return "#{dbp.name}:#{remote_name}" if dbp
          Severity: Minor
          Found in src/api/app/models/project.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 cleanup_linking_repos has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
          Open

            def cleanup_linking_repos
              # replace links to this project repositories with links to the "deleted" repository
              find_repos(:linking_repositories) do |linking_repository|
                linking_repository.path_elements.includes(:link).find_each do |path_element|
                  next unless path_element.link.db_project_id == id && path_element.repository.db_project_id != id
          Severity: Minor
          Found in src/api/app/models/project.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 delete_on_backend has a Cognitive Complexity of 9 (exceeds 8 allowed). Consider refactoring.
          Open

            def delete_on_backend
              if CONFIG['global_write_through'] && !@commit_opts[:no_backend_write]
                begin
                  options = { comment: @commit_opts[:comment] }
                  options[:user] = @commit_opts[:login] || User.session!.login
          Severity: Minor
          Found in src/api/app/models/project.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

                unless linking_target_repositories.empty?
                  str = linking_target_repositories.map { |l| "#{l.project.name}/#{l.name}" }.join("\n")
                  return { error: "Unable to delete repository; following target repositories depend on this project:\n#{str}" }
          Severity: Minor
          Found in src/api/app/models/project.rb and 1 other location - About 15 mins to fix
          src/api/app/models/project.rb on lines 380..382

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

          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

                unless linking_repositories.empty?
                  str = linking_repositories.map! { |l| "#{l.project.name}/#{l.name}" }.join("\n")
                  return { error: "Unable to delete repository; following repositories depend on this project:\n#{str}" }
          Severity: Minor
          Found in src/api/app/models/project.rb and 1 other location - About 15 mins to fix
          src/api/app/models/project.rb on lines 385..387

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

          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