openSUSE/open-build-service

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

Summary

Maintainability
F
5 days
Test Coverage
A
98%

Method create_branch_packages has a Cognitive Complexity of 67 (exceeds 8 allowed). Consider refactoring.
Open

  def create_branch_packages(tprj)
    # collect also the needed repositories here
    response = nil
    @packages.each do |p|
      raise CanNotBranchPackage, "project is developed at #{p[:link_target_project].scmsync}. Fork it instead." if p[:link_target_project].try(:scmsync).present?
Severity: Minor
Found in src/api/app/models/branch_package.rb - About 1 day 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 determine_details_about_package_to_branch has a Cognitive Complexity of 51 (exceeds 8 allowed). Consider refactoring.
Open

  def determine_details_about_package_to_branch(p)
    return unless p[:link_target_project].is_a?(Project) # only for local source projects

    check_for_update_project(p) unless params[:ignoredevel]

Severity: Minor
Found in src/api/app/models/branch_package.rb - About 7 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 find_packages_to_branch has a Cognitive Complexity of 39 (exceeds 8 allowed). Consider refactoring.
Open

  def find_packages_to_branch
    @packages = []
    if params[:request]
      # find packages from request
      req = BsRequest.find_by_number(params[:request])
Severity: Minor
Found in src/api/app/models/branch_package.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 create_branch_packages has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create_branch_packages(tprj)
    # collect also the needed repositories here
    response = nil
    @packages.each do |p|
      raise CanNotBranchPackage, "project is developed at #{p[:link_target_project].scmsync}. Fork it instead." if p[:link_target_project].try(:scmsync).present?
Severity: Major
Found in src/api/app/models/branch_package.rb - About 2 hrs to fix

    Method find_packages_to_branch has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def find_packages_to_branch
        @packages = []
        if params[:request]
          # find packages from request
          req = BsRequest.find_by_number(params[:request])
    Severity: Major
    Found in src/api/app/models/branch_package.rb - About 2 hrs to fix

      Method extend_packages_to_link has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring.
      Open

        def extend_packages_to_link(p)
          return unless p[:package].is_a?(Package) # only for local packages
      
          pkg = p[:package]
          if pkg.is_link?
      Severity: Minor
      Found in src/api/app/models/branch_package.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 create_branch_project has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring.
      Open

        def create_branch_project
          if Project.exists_by_name(@target_project)
            raise CreateProjectNoPermission, "The destination project already exists, so the api can't make it not readable" if @noaccess
      
            tprj = Project.get_by_name(@target_project)
      Severity: Minor
      Found in src/api/app/models/branch_package.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 determine_details_about_package_to_branch has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def determine_details_about_package_to_branch(p)
          return unless p[:link_target_project].is_a?(Project) # only for local source projects
      
          check_for_update_project(p) unless params[:ignoredevel]
      
      
      Severity: Minor
      Found in src/api/app/models/branch_package.rb - About 1 hr to fix

        Method extend_packages_to_link has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def extend_packages_to_link(p)
            return unless p[:package].is_a?(Package) # only for local packages
        
            pkg = p[:package]
            if pkg.is_link?
        Severity: Minor
        Found in src/api/app/models/branch_package.rb - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Confirmed

                    p[:target_package] += ".#{p[:link_target_project].name}" if @extend_names
          Severity: Minor
          Found in src/api/app/models/branch_package.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Confirmed

                      p[:link_target_project] = p[:package].project unless params[:newinstance]
            Severity: Minor
            Found in src/api/app/models/branch_package.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Confirmed

                        ltprj = pkg2.project if ltprj.find_attribute('OBS', 'BranchTarget').nil?
              Severity: Minor
              Found in src/api/app/models/branch_package.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Confirmed

                        raise NotMissingError, "Branch call with missingok parameter but branched source (#{params[:project]}/#{params[:package]}) exists." if Package.exists_by_project_and_name(params[:project], params[:package],
                                                                                                                                                                                                  allow_remote_packages: true)
                Severity: Minor
                Found in src/api/app/models/branch_package.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if prj.is_a?(Project) && prj.find_attribute('OBS', 'BranchTarget')
                            @copy_from_devel = true
                          elsif pkg
                            prj = pkg.project
                            tpkg_name ||= pkg.releasename
                  Severity: Minor
                  Found in src/api/app/models/branch_package.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Confirmed

                              p[:target_package] = params[:target_package] if params[:target_package]
                    Severity: Minor
                    Found in src/api/app/models/branch_package.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Confirmed

                                next if pkg2.nil? || @packages.pluck(:package).include?(pkg2) # avoid double instances
                      Severity: Minor
                      Found in src/api/app/models/branch_package.rb - About 45 mins to fix

                        Method branch has a Cognitive Complexity of 9 (exceeds 8 allowed). Consider refactoring.
                        Open

                          def branch
                            #
                            # 1) BaseProject <-- 2) UpdateProject <-- 3) DevelProject/Package
                            # X) BranchProject
                            #
                        Severity: Minor
                        Found in src/api/app/models/branch_package.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

                                  logger.info "Found package instance #{p.project.name}/#{p.name} for attribute #{at.name} with value #{params[:value]}"
                                  @packages.push(base_project: p.project, link_target_project: p.project, package: p, target_package: "#{p.name}.#{p.project.name}")
                        Severity: Minor
                        Found in src/api/app/models/branch_package.rb and 1 other location - About 50 mins to fix
                        src/api/app/models/branch_package.rb on lines 466..467

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

                        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

                                  logger.info "Found package instance #{p.project.name}/#{p.name} for attribute #{at.name} and given package name #{params[:package]}"
                                  @packages.push(base_project: p.project, link_target_project: p.project, package: p, target_package: "#{p.name}.#{p.project.name}")
                        Severity: Minor
                        Found in src/api/app/models/branch_package.rb and 1 other location - About 50 mins to fix
                        src/api/app/models/branch_package.rb on lines 458..459

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

                        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