next-l/enju_leaf

View on GitHub
app/controllers/manifestations_controller.rb

Summary

Maintainability
F
1 wk
Test Coverage
B
81%

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

  def index
    mode = params[:mode]
    if mode == 'add'
      unless current_user.try(:has_role?, 'Librarian')
        access_denied
Severity: Minor
Found in app/controllers/manifestations_controller.rb - About 2 days 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 manifestations_controller.rb has 700 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ManifestationsController < ApplicationController
  before_action :set_manifestation, only: [:show, :edit, :update, :destroy]
  before_action :check_policy, only: [:index, :new, :create]
  before_action :authenticate_user!, only: :edit
  before_action :get_agent, :get_manifestation, except: [:create, :update, :destroy]
Severity: Major
Found in app/controllers/manifestations_controller.rb - About 1 day to fix

    Method index has 199 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def index
        mode = params[:mode]
        if mode == 'add'
          unless current_user.try(:has_role?, 'Librarian')
            access_denied
    Severity: Major
    Found in app/controllers/manifestations_controller.rb - About 7 hrs to fix

      Method set_acquisition_date has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_acquisition_date(query, options)
          unless options[:acquired_from].blank? && options[:acquired_until].blank?
            options[:acquired_from].to_s.gsub!(/\D/, '')
            options[:acquired_until].to_s.gsub!(/\D/, '')
      
      
      Severity: Minor
      Found in app/controllers/manifestations_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

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

        def make_query(query, options = {})
          # TODO: integerやstringもqfに含める
          query = query.to_s.strip
      
          if query.size == 1
      Severity: Minor
      Found in app/controllers/manifestations_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 make_query has 82 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def make_query(query, options = {})
          # TODO: integerやstringもqfに含める
          query = query.to_s.strip
      
          if query.size == 1
      Severity: Major
      Found in app/controllers/manifestations_controller.rb - About 3 hrs to fix

        Method parse_pub_date has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

          def parse_pub_date(options)
            pub_date = {}
            if options[:pub_date_from].blank?
              pub_date[:from] = "*"
            else
        Severity: Minor
        Found in app/controllers/manifestations_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 manifestation_params has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def manifestation_params
            params.require(:manifestation).permit(
              :original_title, :title_alternative, :title_transcription,
              :manifestation_identifier, :date_copyrighted,
              :access_address, :language_id, :carrier_type_id, :start_page,
        Severity: Major
        Found in app/controllers/manifestations_controller.rb - About 3 hrs to fix

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

            def edit
              unless current_user.has_role?('Librarian')
                unless params[:mode] == 'tag_edit'
                  access_denied
                  return
          Severity: Minor
          Found in app/controllers/manifestations_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 show has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def show
              case params[:mode]
              when 'send_email'
                if user_signed_in?
                  Notifier.manifestation_info(current_user.id, @manifestation.id).deliver_later
          Severity: Minor
          Found in app/controllers/manifestations_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 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def show
              case params[:mode]
              when 'send_email'
                if user_signed_in?
                  Notifier.manifestation_info(current_user.id, @manifestation.id).deliver_later
          Severity: Minor
          Found in app/controllers/manifestations_controller.rb - About 1 hr to fix

            Method set_acquisition_date has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def set_acquisition_date(query, options)
                unless options[:acquired_from].blank? && options[:acquired_until].blank?
                  options[:acquired_from].to_s.gsub!(/\D/, '')
                  options[:acquired_until].to_s.gsub!(/\D/, '')
            
            
            Severity: Minor
            Found in app/controllers/manifestations_controller.rb - About 1 hr to fix

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

                def parse_pub_date(options)
                  pub_date = {}
                  if options[:pub_date_from].blank?
                    pub_date[:from] = "*"
                  else
              Severity: Minor
              Found in app/controllers/manifestations_controller.rb - About 1 hr to fix

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

                  def render_mode(mode)
                    case mode
                    when 'holding'
                      render partial: 'manifestations/show_holding', locals: {manifestation: @manifestation}
                    when 'tag_edit'
                Severity: Minor
                Found in app/controllers/manifestations_controller.rb - About 1 hr to fix

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

                    def create
                      @manifestation = Manifestation.new(manifestation_params)
                      parent = Manifestation.find_by(id: @manifestation.parent_id)
                      unless @manifestation.original_title?
                        @manifestation.original_title = @manifestation.attachment.filename
                  Severity: Minor
                  Found in app/controllers/manifestations_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 render_mode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def render_mode(mode)
                      case mode
                      when 'holding'
                        render partial: 'manifestations/show_holding', locals: {manifestation: @manifestation}
                      when 'tag_edit'
                  Severity: Minor
                  Found in app/controllers/manifestations_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

                      if options[:pub_date_from].blank?
                        pub_date[:from] = "*"
                      else
                        year = options[:pub_date_from].to_s.gsub(/\D/, '').rjust(4, "0")
                        if year.length == 4
                  Severity: Major
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/manifestations_controller.rb on lines 742..752

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

                  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 options[:pub_date_until].blank?
                        pub_date[:until] = "*"
                      else
                        year = options[:pub_date_until].to_s.gsub(/\D/, '').rjust(4, "0")
                        if year.length == 4
                  Severity: Major
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/manifestations_controller.rb on lines 728..738

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

                  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 options[:acquired_from].blank?
                          acquisition_date[:from] = "*"
                        else
                          year = options[:acquired_from].rjust(4, "0")
                          if year.length == 4
                  Severity: Major
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/manifestations_controller.rb on lines 786..796

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

                  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 options[:acquired_until].blank?
                          acquisition_date[:until] = "*"
                        else
                          year = options[:acquired_until].rjust(4, "0")
                          if year.length == 4
                  Severity: Major
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/manifestations_controller.rb on lines 772..782

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

                  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

                        {contributors_attributes: [
                          :id, :last_name, :middle_name, :first_name,
                          :last_name_transcription, :middle_name_transcription,
                          :first_name_transcription, :corporate_name,
                          :corporate_name_transcription,
                  Severity: Minor
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 20 mins to fix
                  app/controllers/manifestations_controller.rb on lines 472..483

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

                  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

                        {publishers_attributes: [
                          :id, :last_name, :middle_name, :first_name,
                          :last_name_transcription, :middle_name_transcription,
                          :first_name_transcription, :corporate_name,
                          :corporate_name_transcription,
                  Severity: Minor
                  Found in app/controllers/manifestations_controller.rb and 1 other location - About 20 mins to fix
                  app/controllers/manifestations_controller.rb on lines 460..471

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

                  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