ucsdlib/damspas

View on GitHub
app/helpers/dams_objects_helper.rb

Summary

Maintainability
D
2 days
Test Coverage

File dams_objects_helper.rb has 524 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "base64"
require "openssl"

module DamsObjectsHelper
  include Dams::ControllerHelper
Severity: Major
Found in app/helpers/dams_objects_helper.rb - About 1 day to fix

    Method select_file has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

      def select_file( params )
        document  = params[:document]
        component = params[:component]
        max_size  = params[:quality]
        type      = params[:type]
    Severity: Minor
    Found in app/helpers/dams_objects_helper.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 select_file has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def select_file( params )
        document  = params[:document]
        component = params[:component]
        max_size  = params[:quality]
        type      = params[:type]
    Severity: Minor
    Found in app/helpers/dams_objects_helper.rb - About 1 hr to fix

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

          def grabTitle(parameters={})
      
              p = {:componentIndex=>nil}.merge(parameters)
              componentIndex = p[:componentIndex]
      
      
      Severity: Minor
      Found in app/helpers/dams_objects_helper.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 file_use has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

       def file_use(parameters, types)
         fieldData = file_data(parameters)
          result = nil
      
          if fieldData != nil
      Severity: Minor
      Found in app/helpers/dams_objects_helper.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 grabDisplayFile has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def grabDisplayFile(parameters={})
      
              p = {:componentIndex=>nil,:quality=>'preview'}.merge(parameters)
              componentIndex = p[:componentIndex]
              validQualities = Set.new ['icon', 'thumbnail', 'preview', 'large', 'huge']
      Severity: Minor
      Found in app/helpers/dams_objects_helper.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_display_file has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def render_display_file( params )
          files = render_file (params)
      
          if files.has_key?(:display)
            display_file = files[:display]
      Severity: Minor
      Found in app/helpers/dams_objects_helper.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 getTitle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def getTitle
            data_arr=[]
            
            fieldData=getFieldData('title_json_tesim')
            title_value=''
      Severity: Minor
      Found in app/helpers/dams_objects_helper.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

      Avoid deeply nested control flow statements.
      Open

                  if (display_json == nil || file_dim.to_i > display_dim) && use != nil && (not use.end_with?("-source") )
                    display_json = fjson
                    display_dim  = file_dim.to_i
                  end
      Severity: Major
      Found in app/helpers/dams_objects_helper.rb - About 45 mins to fix

        Method grabRestrictedText has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def grabRestrictedText(data)
        
            result = nil
        
            if data != nil
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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

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

          def display_tree(components)
            @checked = []
            if !components.nil? && !components.empty? 
              concat '<ul class="unstyled">'.html_safe
              components.each do |i|
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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 render_node_HTML has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def render_node_HTML(index, is_parent_node)
            @checked[index]= true
            fileUse = grabFileUse(:componentIndex=>index)
            btnAttrForFiles = "onClick='dp.COV.showComponent(#{index});'"
            btnID = "node-btn-#{index}"
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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 grabWowzaURL has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def grabWowzaURL(fieldData,objid,cmpid)
            if fieldData != nil
              fieldData.each do |datum|
                files = JSON.parse(datum)
                if files['use'] == 'audio-service' || files['use'] == 'video-service'
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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 export_as_openurl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

           def export_as_openurl
                query_string = []
                query_string << "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator"
                field_map = {
                  'title' => getTitle,
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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 grabPDFFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def grabPDFFile(parameters={})
            fieldData = file_data(parameters)
            result = nil
        
            if fieldData != nil
        Severity: Minor
        Found in app/helpers/dams_objects_helper.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 grabIcon(fileUse)
                icon = grabFileType(fileUse)
                case icon
                    when 'image'
                        icon = 'glyphicon glyphicon-picture'
        Severity: Minor
        Found in app/helpers/dams_objects_helper.rb and 1 other location - About 25 mins to fix
        app/helpers/catalog_helper.rb on lines 209..223

        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

                if fieldData != nil
                    fieldData.each do |datum|
                        files = JSON.parse(datum)
                        if files["use"].end_with?("-source")
                            result = files["id"]
        Severity: Minor
        Found in app/helpers/dams_objects_helper.rb and 1 other location - About 15 mins to fix
        app/helpers/catalog_helper.rb on lines 191..197

        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