redmine/redmine

View on GitHub
app/controllers/wiki_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Method update has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @page = @wiki.find_or_new_page(params[:id])
    return render_403 unless editable?

    was_new_page = @page.new_record?
Severity: Minor
Found in app/controllers/wiki_controller.rb - About 4 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 wiki_controller.rb has 299 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class WikiController < ApplicationController
  default_search_scope :wiki_pages
  before_action :find_wiki, :authorize
  before_action :find_existing_or_new_page, :only => [:show, :edit]
  before_action :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
Severity: Minor
Found in app/controllers/wiki_controller.rb - About 3 hrs to fix

    Class WikiController has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class WikiController < ApplicationController
      default_search_scope :wiki_pages
      before_action :find_wiki, :authorize
      before_action :find_existing_or_new_page, :only => [:show, :edit]
      before_action :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
    Severity: Minor
    Found in app/controllers/wiki_controller.rb - About 2 hrs to fix

      Method update has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def update
          @page = @wiki.find_or_new_page(params[:id])
          return render_403 unless editable?
      
          was_new_page = @page.new_record?
      Severity: Major
      Found in app/controllers/wiki_controller.rb - About 2 hrs to fix

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

          def destroy
            return render_403 unless editable?
        
            @descendants_count = @page.descendants.size
            if @descendants_count > 0
        Severity: Minor
        Found in app/controllers/wiki_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 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def show
            if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
              deny_access
              return
            end
        Severity: Minor
        Found in app/controllers/wiki_controller.rb - About 1 hr to fix

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

            def edit
              return render_403 unless editable?
          
              if @page.new_record?
                if params[:parent].present?
          Severity: Minor
          Found in app/controllers/wiki_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 a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def show
              if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
                deny_access
                return
              end
          Severity: Minor
          Found in app/controllers/wiki_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 destroy has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def destroy
              return render_403 unless editable?
          
              @descendants_count = @page.descendants.size
              if @descendants_count > 0
          Severity: Minor
          Found in app/controllers/wiki_controller.rb - About 1 hr to fix

            Method new has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def new
                @page = WikiPage.new(:wiki => @wiki, :title => params[:title])
                unless User.current.allowed_to?(:edit_wiki_pages, @project)
                  render_403
                  return
            Severity: Minor
            Found in app/controllers/wiki_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

            Avoid too many return statements within this method.
            Open

                    return
            Severity: Major
            Found in app/controllers/wiki_controller.rb - About 30 mins to fix

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

                def preview
                  page = @wiki.find_page(params[:id])
                  # page is nil when previewing a new page
                  return render_403 unless page.nil? || editable?(page)
              
              
              Severity: Minor
              Found in app/controllers/wiki_controller.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

              There are no issues that match your filters.

              Category
              Status