archivesspace/archivesspace

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

Summary

Maintainability
D
3 days
Test Coverage

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

  def create
    handle_crud(:instance => :archival_object,
                :find_opts => find_opts,
                :on_invalid => ->() {
                  if inline?
Severity: Minor
Found in frontend/app/controllers/archival_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

File archival_objects_controller.rb has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ArchivalObjectsController < ApplicationController

  set_access_control  "view_repository" => [:index, :show, :models_in_graph],
                      "update_resource_record" => [:new, :edit, :create, :update, :transfer, :rde, :add_children, :publish, :unpublish, :accept_children, :validate_rows],
                      "suppress_archival_record" => [:suppress, :unsuppress],
Severity: Minor
Found in frontend/app/controllers/archival_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(:archival_object).find(params[:id])
        @resource_uri = @parent['resource']['ref']
    
        if params[:archival_record_children].blank? or params[:archival_record_children]["children"].blank?
    Severity: Minor
    Found in frontend/app/controllers/archival_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 create has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create
        handle_crud(:instance => :archival_object,
                    :find_opts => find_opts,
                    :on_invalid => ->() {
                      if inline?
    Severity: Minor
    Found in frontend/app/controllers/archival_objects_controller.rb - About 1 hr to fix

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

        def add_children
          @parent = JSONModel(:archival_object).find(params[:id])
          @resource_uri = @parent['resource']['ref']
      
          if params[:archival_record_children].blank? or params[:archival_record_children]["children"].blank?
      Severity: Minor
      Found in frontend/app/controllers/archival_objects_controller.rb - About 1 hr to fix

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

          def update
            params['archival_object']['position'] = params['archival_object']['position'].to_i if params['archival_object']['position']
        
            @archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
            resource = @archival_object['resource']['_resolved']
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_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

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

          def add_children
            @parent = JSONModel(:archival_object).find(params[:id])
            @resource_uri = @parent['resource']['ref']
        
            if params[:archival_record_children].blank? or params[:archival_record_children]["children"].blank?
        Severity: Major
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 5 hrs to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 182..226

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

        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 publish
            @archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
        
            response = JSONModel::HTTP.post_form("#{@archival_object.uri}/publish")
        
        
        Severity: Major
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 1 hr to fix
        frontend/app/controllers/archival_objects_controller.rb on lines 296..307

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

        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 unpublish
            @archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
        
            response = JSONModel::HTTP.post_form("#{@archival_object.uri}/unpublish")
        
        
        Severity: Major
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 1 hr to fix
        frontend/app/controllers/archival_objects_controller.rb on lines 281..292

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

        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 8 locations. Consider refactoring.
        Open

          def update_defaults
            begin
              DefaultValues.from_hash({
                                        "record_type" => "archival_object",
                                        "lock_version" => params[:archival_object].delete('lock_version'),
        Severity: Major
        Found in frontend/app/controllers/archival_objects_controller.rb and 7 other locations - About 1 hr to fix
        frontend/app/controllers/accessions_controller.rb on lines 69..86
        frontend/app/controllers/classification_terms_controller.rb on lines 135..150
        frontend/app/controllers/classifications_controller.rb on lines 134..149
        frontend/app/controllers/digital_object_components_controller.rb on lines 139..156
        frontend/app/controllers/events_controller.rb on lines 146..161
        frontend/app/controllers/locations_controller.rb on lines 112..127
        frontend/app/controllers/subjects_controller.rb on lines 110..125

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

        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
            archival_object = JSONModel(:archival_object).find(params[:id])
            archival_object.set_suppressed(false)
        
            flash[:success] = I18n.t("archival_object._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:archival_object => archival_object).enable_parse_mixed_content!(url_for(:root)))
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 1 hr to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 238..243

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

        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
            archival_object = JSONModel(:archival_object).find(params[:id])
            archival_object.set_suppressed(true)
        
            flash[:success] = I18n.t("archival_object._frontend.messages.suppressed", JSONModelI18nWrapper.new(:archival_object => archival_object).enable_parse_mixed_content!(url_for(:root)))
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 1 hr to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 229..234

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

        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

                          success_message = @archival_object.parent ?
                                              I18n.t("archival_object._frontend.messages.created_with_parent", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved'], :parent => @archival_object['parent']['_resolved']).enable_parse_mixed_content!(url_for(:root))) :
                                              I18n.t("archival_object._frontend.messages.created", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved']).enable_parse_mixed_content!(url_for(:root)))
        
                          if params.has_key?(:plus_one)
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 50 mins to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 51..55

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

        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 models_in_graph
            list_uri = JSONModel(:archival_object).uri_for(params[:id]) + "/models_in_graph"
            list = JSONModel::HTTP.get_json(list_uri)
        
            render :json => list.select { |type| type != "lang_material" }.map {|type|
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 50 mins to fix
        frontend/app/controllers/resources_controller.rb on lines 366..373

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

        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 @archival_object["is_slug_auto"] == false &&
                             @archival_object["slug"] == nil &&
                             params["archival_object"] &&
                             params["archival_object"]["is_slug_auto"] == "1"
        
        
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 45 mins to fix
        frontend/app/controllers/classification_terms_controller.rb on lines 47..57

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

        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 validate_rows
            row_data = cleanup_params_for_schema(params[:archival_record_children], JSONModel(:archival_record_children).schema)
        
            # build the AOC record but don't bother validating it yet...
            aoc = ArchivalObjectChildren.from_hash(row_data, false, true)
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 25 mins to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 172..180

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

        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 defaults
            defaults = DefaultValues.get 'archival_object'
        
            values = defaults ? defaults.form_values : {}
        
        
        Severity: Minor
        Found in frontend/app/controllers/archival_objects_controller.rb and 1 other location - About 15 mins to fix
        frontend/app/controllers/digital_object_components_controller.rb on lines 126..135

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

        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