otwcode/otwarchive

View on GitHub
app/controllers/bookmarks_controller.rb

Summary

Maintainability
F
3 days
Test Coverage

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

  def index
    if @bookmarkable
      access_denied unless is_admin? || @bookmarkable.visible?
      @bookmarks = @bookmarkable.bookmarks.is_public.order_by_created_at.paginate(page: params[:page], per_page: ArchiveConfig.ITEMS_PER_PAGE)
    else
Severity: Minor
Found in app/controllers/bookmarks_controller.rb - About 6 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 update has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    new_collections = []
    unapproved_collections = []
    errors = []
    bookmark_params[:collection_names]&.split(",")&.map(&:strip)&.uniq&.each do |collection_name|
Severity: Minor
Found in app/controllers/bookmarks_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 bookmarks_controller.rb has 322 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class BookmarksController < ApplicationController
  before_action :load_collection
  before_action :load_owner, only: [:index]
  before_action :load_bookmarkable, only: [:index, :new, :create]
  before_action :users_only, only: [:new, :create, :edit, :update]
Severity: Minor
Found in app/controllers/bookmarks_controller.rb - About 3 hrs to fix

    Method load_owner has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def load_owner
        if params[:user_id].present?
          @user = User.find_by(login: params[:user_id])
          unless @user
            raise ActiveRecord::RecordNotFound, "Couldn't find user named '#{params[:user_id]}'"
    Severity: Minor
    Found in app/controllers/bookmarks_controller.rb - About 2 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 index has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def index
        if @bookmarkable
          access_denied unless is_admin? || @bookmarkable.visible?
          @bookmarks = @bookmarkable.bookmarks.is_public.order_by_created_at.paginate(page: params[:page], per_page: ArchiveConfig.ITEMS_PER_PAGE)
        else
    Severity: Major
    Found in app/controllers/bookmarks_controller.rb - About 2 hrs to fix

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

        def update
          new_collections = []
          unapproved_collections = []
          errors = []
          bookmark_params[:collection_names]&.split(",")&.map(&:strip)&.uniq&.each do |collection_name|
      Severity: Minor
      Found in app/controllers/bookmarks_controller.rb - About 1 hr to fix

        Method load_owner has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def load_owner
            if params[:user_id].present?
              @user = User.find_by(login: params[:user_id])
              unless @user
                raise ActiveRecord::RecordNotFound, "Couldn't find user named '#{params[:user_id]}'"
        Severity: Minor
        Found in app/controllers/bookmarks_controller.rb - About 1 hr to fix

          Method bookmark_search_params has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def bookmark_search_params
              params.require(:bookmark_search).permit(
                :bookmark_query,
                :bookmarkable_query,
                :bookmarker,
          Severity: Minor
          Found in app/controllers/bookmarks_controller.rb - About 1 hr to fix

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

              def search
                @languages = Language.default_order
                options = params[:bookmark_search].present? ? bookmark_search_params : {}
                options.merge!(page: params[:page]) if params[:page].present?
                options[:show_private] = false
            Severity: Minor
            Found in app/controllers/bookmarks_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 share has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def share
                if request.xhr?
                  if @bookmark.bookmarkable.is_a?(Work) && @bookmark.bookmarkable.unrevealed?
                    render template: "errors/404", status: :not_found
                  else
            Severity: Minor
            Found in app/controllers/bookmarks_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 check_pseud_ownership has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def check_pseud_ownership
                if params[:bookmark][:pseud_id]
                  pseud = Pseud.find(bookmark_params[:pseud_id])
                  unless pseud && current_user && current_user.pseuds.include?(pseud)
                    flash[:error] = ts("You can't bookmark with that pseud.")
            Severity: Minor
            Found in app/controllers/bookmarks_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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              def index_page_title
                if @owner.present?
                  owner_name = case @owner.class.to_s
                               when 'Pseud'
                                 @owner.name
            Severity: Minor
            Found in app/controllers/bookmarks_controller.rb and 1 other location - About 35 mins to fix
            app/controllers/works_controller.rb on lines 840..856

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

            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

                  if params[:include_bookmark_search].present?
                    params[:include_bookmark_search].keys.each do |key|
                      options[key] ||= []
                      options[key] << params[:include_bookmark_search][key]
                      options[key].flatten!
            Severity: Minor
            Found in app/controllers/bookmarks_controller.rb and 1 other location - About 25 mins to fix
            app/controllers/works_controller.rb on lines 69..73

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

            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

                  pseud = Pseud.find(bookmark_params[:pseud_id])
                  unless pseud && current_user && current_user.pseuds.include?(pseud)
                    flash[:error] = ts("You can't bookmark with that pseud.")
                    redirect_to root_path and return
                  end
            Severity: Minor
            Found in app/controllers/bookmarks_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/tag_set_nominations_controller.rb on lines 12..16

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

            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