Noosfero/noosfero

View on GitHub
app/controllers/public/content_viewer_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Method view_page has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  def view_page
    path = get_path(params[:page], params[:format])

    @version = params[:version].to_i
    @npage = params[:npage] || "1"
Severity: Minor
Found in app/controllers/public/content_viewer_controller.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

Class ContentViewerController has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class ContentViewerController < ApplicationController
  needs_profile

  helper ProfileHelper
  helper TagsHelper
Severity: Minor
Found in app/controllers/public/content_viewer_controller.rb - About 2 hrs to fix

    Method view_page has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def view_page
        path = get_path(params[:page], params[:format])
    
        @version = params[:version].to_i
        @npage = params[:npage] || "1"
    Severity: Minor
    Found in app/controllers/public/content_viewer_controller.rb - About 1 hr to fix

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

          def redirect_to_translation
            locale = FastGettext.locale
            if !@page.language.nil? && @page.language != locale
              translations = [@page.native_translation] + @page.native_translation.translations
              urls = translations.map { |t| URI.parse(url_for(t.url)).path }
      Severity: Minor
      Found in app/controllers/public/content_viewer_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 rendered_file_download has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def rendered_file_download(view = nil)
            if @page.download? view
              data = @page.data
      
              # TODO test the condition
      Severity: Minor
      Found in app/controllers/public/content_viewer_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

      Avoid too many return statements within this method.
      Open

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

        Avoid too many return statements within this method.
        Open

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

          Avoid too many return statements within this method.
          Open

                return if rendered_versioned_article
          Severity: Major
          Found in app/controllers/public/content_viewer_controller.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                return if rendered_file_download(params[:view])
            Severity: Major
            Found in app/controllers/public/content_viewer_controller.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                    return render partial: "comment/comment", collection: @comments
              Severity: Major
              Found in app/controllers/public/content_viewer_controller.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                    redirect_to_translation && (return) if @page.profile.redirect_l10n
                Severity: Major
                Found in app/controllers/public/content_viewer_controller.rb - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status