openSUSE/open-build-service

View on GitHub
src/api/app/controllers/webui/package_controller.rb

Summary

Maintainability
F
5 days
Test Coverage

File package_controller.rb has 726 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Webui::PackageController < Webui::WebuiController
  include ParsePackageDiff
  include Webui::PackageHelper
  include Webui::ManageRelationships
  include BuildLogSupport
Severity: Major
Found in src/api/app/controllers/webui/package_controller.rb - About 1 day to fix

    Class PackageController has 50 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Webui::PackageController < Webui::WebuiController
      include ParsePackageDiff
      include Webui::PackageHelper
      include Webui::ManageRelationships
      include BuildLogSupport
    Severity: Minor
    Found in src/api/app/controllers/webui/package_controller.rb - About 7 hrs to fix

      Method set_file_details has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_file_details
          @forced_unexpand ||= ''
      
          # check source access
          @files = []
      Severity: Minor
      Found in src/api/app/controllers/webui/package_controller.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 rdiff has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def rdiff
          @last_rev = @package.dir_hash['rev']
          @linkinfo = @package.linkinfo
          if params[:oproject]
            @oproject = ::Project.find_by_name(params[:oproject])
      Severity: Minor
      Found in src/api/app/controllers/webui/package_controller.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 update_build_log has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def update_build_log
          # Make sure objects don't contain invalid chars (eg. '../')
          @repo = @project.repositories.find_by(name: params[:repository]).try(:name)
          unless @repo
            @errors = "Couldn't find repository '#{params[:repository]}'. We don't have build log for this repository"
      Severity: Minor
      Found in src/api/app/controllers/webui/package_controller.rb - About 1 hr to fix

        Method update_build_log has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_build_log
            # Make sure objects don't contain invalid chars (eg. '../')
            @repo = @project.repositories.find_by(name: params[:repository]).try(:name)
            unless @repo
              @errors = "Couldn't find repository '#{params[:repository]}'. We don't have build log for this repository"
        Severity: Minor
        Found in src/api/app/controllers/webui/package_controller.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 show has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def show
            if request.bot?
              params.delete(:rev)
              params.delete(:srcmd5)
              @expand = 0
        Severity: Minor
        Found in src/api/app/controllers/webui/package_controller.rb - About 1 hr to fix

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

            def view_file
              @filename = params[:filename] || params[:file] || ''
              if Package.is_binary_file?(@filename) # We don't want to display binary files
                flash[:error] = "Unable to display binary file #{@filename}"
                redirect_back(fallback_location: { action: :show, project: @project, package: @package })
          Severity: Minor
          Found in src/api/app/controllers/webui/package_controller.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 view_file has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def view_file
              @filename = params[:filename] || params[:file] || ''
              if Package.is_binary_file?(@filename) # We don't want to display binary files
                flash[:error] = "Unable to display binary file #{@filename}"
                redirect_back(fallback_location: { action: :show, project: @project, package: @package })
          Severity: Minor
          Found in src/api/app/controllers/webui/package_controller.rb - About 1 hr to fix

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

              def dependency
                dependant_project = Project.find_by_name(params[:dependant_project]) || Project.find_remote_project(params[:dependant_project]).try(:first)
                unless dependant_project
                  flash[:error] = "Project '#{params[:dependant_project]}' is invalid."
                  redirect_back(fallback_location: root_path)
            Severity: Minor
            Found in src/api/app/controllers/webui/package_controller.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 rdiff has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def rdiff
                @last_rev = @package.dir_hash['rev']
                @linkinfo = @package.linkinfo
                if params[:oproject]
                  @oproject = ::Project.find_by_name(params[:oproject])
            Severity: Minor
            Found in src/api/app/controllers/webui/package_controller.rb - About 1 hr to fix

              Method dependency has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def dependency
                  dependant_project = Project.find_by_name(params[:dependant_project]) || Project.find_remote_project(params[:dependant_project]).try(:first)
                  unless dependant_project
                    flash[:error] = "Project '#{params[:dependant_project]}' is invalid."
                    redirect_back(fallback_location: root_path)
              Severity: Minor
              Found in src/api/app/controllers/webui/package_controller.rb - About 1 hr to fix

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

                  def show
                    if request.bot?
                      params.delete(:rev)
                      params.delete(:srcmd5)
                      @expand = 0
                Severity: Minor
                Found in src/api/app/controllers/webui/package_controller.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 binaries has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Wontfix

                  def binaries
                    @repository = params[:repository]
                    @package_name = params[:package]
                
                    results_from_backend = Buildresult.find_hashed(project: @project, package: @package_name, repository: @repository, view: ['binarylist', 'status'])
                Severity: Minor
                Found in src/api/app/controllers/webui/package_controller.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 save_meta has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def save_meta
                    errors = []
                
                    authorize @package, :save_meta_update?
                
                
                Severity: Minor
                Found in src/api/app/controllers/webui/package_controller.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 rpmlint_result has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def rpmlint_result
                    @repo_arch_hash = {}
                    @buildresult = Buildresult.find_hashed(project: @project.to_param, package: @package.to_param, view: 'status')
                    repos = [] # Temp var
                    if @buildresult
                Severity: Minor
                Found in src/api/app/controllers/webui/package_controller.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 links_for_binaries_action has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Invalid

                  def links_for_binaries_action(project, package_name, repository, architecture, filename)
                Severity: Minor
                Found in src/api/app/controllers/webui/package_controller.rb - About 35 mins to fix

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

                    def revisions
                      unless @package.check_source_access?
                        flash[:error] = 'Could not access revisions'
                        redirect_to action: :show, project: @project.name, package: @package.name
                        return
                  Severity: Minor
                  Found in src/api/app/controllers/webui/package_controller.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 check_build_log_access has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def check_build_log_access
                      if ::Project.exists_by_name(params[:project])
                        @project = ::Project.get_by_name(params[:project])
                      else
                        redirect_to root_path, error: "Couldn't find project '#{params[:project]}'. Are you sure it still exists?"
                  Severity: Minor
                  Found in src/api/app/controllers/webui/package_controller.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 find_last_req has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def find_last_req
                      if @oproject && @opackage
                        last_req = BsRequestAction.where(target_project: @oproject,
                                                         target_package: @opackage,
                                                         source_project: @package.project,
                  Severity: Minor
                  Found in src/api/app/controllers/webui/package_controller.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

                    def update
                      authorize @package, :update?
                      respond_to do |format|
                        if @package.update(package_details_params)
                          format.html do
                  Severity: Minor
                  Found in src/api/app/controllers/webui/package_controller.rb and 1 other location - About 55 mins to fix
                  src/api/app/controllers/webui/project_controller.rb on lines 232..246

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

                  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