indentlabs/notebook

View on GitHub
app/controllers/content_controller.rb

Summary

Maintainability
F
4 days
Test Coverage

File content_controller.rb has 525 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ContentController < ApplicationController
  before_action :authenticate_user!, except: [:show, :changelog, :api_sort] \
    + Rails.application.config.content_types[:all_non_universe].map { |type| type.name.downcase.pluralize.to_sym }

  skip_before_action :cache_most_used_page_information, only: [
Severity: Major
Found in app/controllers/content_controller.rb - About 1 day to fix

    Class ContentController has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ContentController < ApplicationController
      before_action :authenticate_user!, except: [:show, :changelog, :api_sort] \
        + Rails.application.config.content_types[:all_non_universe].map { |type| type.name.downcase.pluralize.to_sym }
    
      skip_before_action :cache_most_used_page_information, only: [
    Severity: Minor
    Found in app/controllers/content_controller.rb - About 5 hrs to fix

      Method create has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          content_type = content_type_from_controller(self.class)
          initialize_object
      
          unless current_user.can_create?(content_type) \
      Severity: Minor
      Found in app/controllers/content_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

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

        def api_sort
          sort_params = params.permit(:content_id, :intended_position, :sortable_class)
          sortable_class = sort_params[:sortable_class].constantize # todo audit
          return unless sortable_class
      
      
      Severity: Minor
      Found in app/controllers/content_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 new has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def new
          @content = content_type_from_controller(self.class)
            .new(user: current_user)
            .tap { |content| 
              content.name        = "New #{content.class.name}"
      Severity: Minor
      Found in app/controllers/content_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 has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def update
          # TODO: most things are stripped out now that we're using per-field updates, so we should
          # audit what's left of this function and what needs to stay
          content_type = content_type_from_controller(self.class)
          @content = content_type.with_deleted.find(params[:id])
      Severity: Minor
      Found in app/controllers/content_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 index has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def index
          @content_type_class = content_type_from_controller(self.class)
          pluralized_content_name = @content_type_class.name.downcase.pluralize
      
          @page_title = "My #{pluralized_content_name}"
      Severity: Minor
      Found in app/controllers/content_controller.rb - About 1 hr to fix

        Method new has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def new
            @content = content_type_from_controller(self.class)
              .new(user: current_user)
              .tap { |content| 
                content.name        = "New #{content.class.name}"
        Severity: Minor
        Found in app/controllers/content_controller.rb - About 1 hr to fix

          Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create
              content_type = content_type_from_controller(self.class)
              initialize_object
          
              unless current_user.can_create?(content_type) \
          Severity: Minor
          Found in app/controllers/content_controller.rb - About 1 hr to fix

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

              def link_field_update
                @attribute_field = AttributeField.find_by(id: params[:field_id].to_i)
                attribute_value = @attribute_field.attribute_values.order('created_at desc').find_or_initialize_by(entity_params)
                attribute_value.user_id ||= current_user.id
            
            
            Severity: Minor
            Found in app/controllers/content_controller.rb - About 1 hr to fix

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

                def update
                  # TODO: most things are stripped out now that we're using per-field updates, so we should
                  # audit what's left of this function and what needs to stay
                  content_type = content_type_from_controller(self.class)
                  @content = content_type.with_deleted.find(params[:id])
              Severity: Minor
              Found in app/controllers/content_controller.rb - About 1 hr to fix

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

                  def show    
                    content_type = content_type_from_controller(self.class)
                    return redirect_to(root_path, notice: "That page doesn't exist!") unless valid_content_types.include?(content_type.name)
                
                    @content = content_type.find_by(id: params[:id])
                Severity: Minor
                Found in app/controllers/content_controller.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 changelog has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def changelog
                    content_type = content_type_from_controller(self.class)
                    return redirect_to root_path unless valid_content_types.include?(content_type.name)
                    @content = content_type.find_by(id: params[:id])
                    return redirect_to(root_path, notice: "You don't have permission to view that content.") if @content.nil?
                Severity: Minor
                Found in app/controllers/content_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 redirect_to root_path, notice: "You don't have permission to view that content."
                Severity: Major
                Found in app/controllers/content_controller.rb - About 30 mins to fix

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

                    def successful_response(url, notice)
                      respond_to do |format|
                        format.html {
                          if params.key?(:override) && params[:override].key?(:redirect_path)
                            redirect_to params[:override][:redirect_path], notice: notice
                  Severity: Minor
                  Found in app/controllers/content_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

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

                    def toggle_archive
                      # todo Since this method is triggered via a GET in floating_action_buttons, a malicious user could technically archive
                      # another user's content if they're able to send that user to a specifically-crafted URL or inject that URL somewhere on
                      # a page (e.g. img src="/characters/1234/toggle_archive"). Since archiving is reversible this seems fine for release, but
                      # is something that should be fixed asap before any abuse happens.
                  Severity: Minor
                  Found in app/controllers/content_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

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

                    def index
                      @content_type_class = content_type_from_controller(self.class)
                      pluralized_content_name = @content_type_class.name.downcase.pluralize
                  
                      @page_title = "My #{pluralized_content_name}"
                  Severity: Minor
                  Found in app/controllers/content_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