archivesspace/archivesspace

View on GitHub
frontend/app/controllers/digital_objects_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File digital_objects_controller.rb has 302 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class DigitalObjectsController < ApplicationController

  set_access_control  "view_repository" => [:index, :show, :tree_root, :tree_node, :tree_waypoint, :node_from_root],
                      "update_digital_object_record" => [:new, :edit, :create, :update, :publish, :accept_children, :rde, :add_children],
                      "delete_archival_record" => [:delete],
Severity: Minor
Found in frontend/app/controllers/digital_objects_controller.rb - About 3 hrs to fix

    Class DigitalObjectsController has 24 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class DigitalObjectsController < ApplicationController
    
      set_access_control  "view_repository" => [:index, :show, :tree_root, :tree_node, :tree_waypoint, :node_from_root],
                          "update_digital_object_record" => [:new, :edit, :create, :update, :publish, :accept_children, :rde, :add_children],
                          "delete_archival_record" => [:delete],
    Severity: Minor
    Found in frontend/app/controllers/digital_objects_controller.rb - About 2 hrs to fix

      Method add_children has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_children
          @parent = JSONModel(:digital_object).find(params[:id])
          @digital_object_uri = @parent.uri
      
          if params[:digital_record_children].blank? or params[:digital_record_children]["children"].blank?
      Severity: Minor
      Found in frontend/app/controllers/digital_objects_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 fetch_tree has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def fetch_tree
          tree = {}
      
          limit_to = if params[:node_uri] && !params[:node_uri].include?("/digital_objects/")
                       params[:node_uri]
      Severity: Minor
      Found in frontend/app/controllers/digital_objects_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 fetch_tree has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def fetch_tree
          tree = {}
      
          limit_to = if params[:node_uri] && !params[:node_uri].include?("/digital_objects/")
                       params[:node_uri]
      Severity: Minor
      Found in frontend/app/controllers/digital_objects_controller.rb - About 1 hr to fix

        Method add_children has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def add_children
            @parent = JSONModel(:digital_object).find(params[:id])
            @digital_object_uri = @parent.uri
        
            if params[:digital_record_children].blank? or params[:digital_record_children]["children"].blank?
        Severity: Minor
        Found in frontend/app/controllers/digital_objects_controller.rb - About 1 hr to fix

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

            def new
              @digital_object = JSONModel(:digital_object).new({:title => t("digital_object.title_default", :default => "")})._always_valid!
          
              if user_prefs['default_values']
                defaults = DefaultValues.get 'digital_object'
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_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 a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def index
              respond_to do |format|
                format.html {
                  @search_data = Search.for_type(session[:repo_id], params[:include_components]==="true" ? ["digital_object", "digital_object_component"] : "digital_object", params_for_backend_search.merge({"facet[]" => SearchResultData.DIGITAL_OBJECT_FACETS}))
                }
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def create
              handle_crud(:instance => :digital_object,
                          :on_invalid => ->() {
                            return render_aspace_partial :partial => "new" if inline?
                            render :action => "new"
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_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

            def index
              respond_to do |format|
                format.html {
                  @search_data = Search.for_type(session[:repo_id], params[:include_components]==="true" ? ["digital_object", "digital_object_component"] : "digital_object", params_for_backend_search.merge({"facet[]" => SearchResultData.DIGITAL_OBJECT_FACETS}))
                }
          Severity: Major
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 1 hr to fix
          frontend/app/controllers/resources_controller.rb on lines 14..23

          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

            def update
              handle_crud(:instance => :digital_object,
                          :obj => JSONModel(:digital_object).find(params[:id], find_opts),
                          :on_invalid => ->() {
                            render_aspace_partial :partial => "edit_inline"
          Severity: Major
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 1 hr to fix
          frontend/app/controllers/classifications_controller.rb on lines 92..110

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

          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

            def update_defaults
              begin
                DefaultValues.from_hash({
                                          "record_type" => "digital_object",
                                          "lock_version" => params[:digital_object].delete('lock_version'),
          Severity: Major
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 1 hr to fix
          frontend/app/controllers/resources_controller.rb on lines 82..99

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

          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

            def tree_waypoint
              digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])
              node_uri = if !params[:node].blank?
                           params[:node]
                         else
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 40 mins to fix
          frontend/app/controllers/classifications_controller.rb on lines 189..200

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

          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[:hash].blank?
                node_id = params[:hash].sub("tree::", "").sub("#", "")
                if node_id.starts_with?("digital_object_component")
                  limit_to = JSONModel(:digital_object_component).uri_for(node_id.sub("digital_object_component_", "").to_i)
                elsif node_id.starts_with?("digital_object")
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 35 mins to fix
          frontend/app/controllers/classifications_controller.rb on lines 216..222

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

          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

            def tree_node
              digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])
              node_uri = if !params[:node].blank?
                           params[:node]
                         else
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 30 mins to fix
          frontend/app/controllers/classifications_controller.rb on lines 177..187

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

          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

            def suppress
              digital_object = JSONModel(:digital_object).find(params[:id])
              digital_object.set_suppressed(true)
          
              flash[:success] = t("digital_object._frontend.messages.suppressed", digital_object_title: digital_object.title)
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 25 mins to fix
          frontend/app/controllers/resources_controller.rb on lines 345..350

          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

            def unsuppress
              digital_object = JSONModel(:digital_object).find(params[:id])
              digital_object.set_suppressed(false)
          
              flash[:success] = t("digital_object._frontend.messages.unsuppressed", digital_object_title: digital_object.title)
          Severity: Minor
          Found in frontend/app/controllers/digital_objects_controller.rb and 1 other location - About 25 mins to fix
          frontend/app/controllers/resources_controller.rb on lines 354..359

          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

          There are no issues that match your filters.

          Category
          Status