hardpixel/action-admin

View on GitHub

Showing 13 of 13 total issues

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

    def input_placeholder
      span    = content_tag :span, 'No items available', class: 'margin-bottom-1'
      icon    = content_tag :i, nil, class: 'mdi mdi-playlist-plus'
      clear   = content_tag :a, 'Clear', data: { clear: "#{input_html_id}-preview" }, class: 'button alert hollow margin-0'
      clear   = content_tag :div, clear, class: 'cell auto'
Severity: Major
Found in app/inputs/action_admin/add_more_input.rb and 1 other location - About 3 hrs to fix
app/inputs/action_admin/schedule_input.rb on lines 17..29

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

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 input_placeholder
      span    = content_tag :span, 'No schedules available', class: 'margin-bottom-1'
      icon    = content_tag :i, nil, class: 'mdi mdi-calendar-clock'
      clear   = content_tag :a, 'Clear', data: { clear: "#{input_html_id}-preview" }, class: 'button alert hollow margin-0'
      clear   = content_tag :div, clear, class: 'cell auto'
Severity: Major
Found in app/inputs/action_admin/schedule_input.rb and 1 other location - About 3 hrs to fix
app/inputs/action_admin/add_more_input.rb on lines 29..41

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

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

Method multiupload_field has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def multiupload_field(name)
          attr_name = :"#{name}"
          attr_curr = :"current_#{name}"
          attr_prev = :"previous_#{name}"

Severity: Minor
Found in lib/action_admin/form/uploadable.rb - About 1 hr to fix

    Method attachment_multiple has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def attachment_multiple(file_url = nil, file_name = nil, file_path = nil, removable = false, media_type = nil)
          image = content_tag :img, nil, src: file_url || image_url('upload'), data: { mime_match: 'image/*', dz_thumbnail: '' }
          video = content_tag :img, nil, src: image_url('video'), data: { mime_match: 'video/*' }
          file  = content_tag :img, nil, src: image_url('file'), data: { mime_match: '*/*' }
          fname = content_tag :span, file_name, class: 'filename', data: { dz_name: '' }
    Severity: Minor
    Found in app/inputs/action_admin/upload_input.rb - About 1 hr to fix

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

              def multiupload_field(name)
                attr_name = :"#{name}"
                attr_curr = :"current_#{name}"
                attr_prev = :"previous_#{name}"
      
      
      Severity: Minor
      Found in lib/action_admin/form/uploadable.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 existing_attachments has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def existing_attachments
            attribute  = object.send(attribute_name)
            thumb_size = input_options.fetch :thumbnail_size, :small
      
            if multiple?
      Severity: Minor
      Found in app/inputs/action_admin/upload_input.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 attachment_preview has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def attachment_preview(file_url = nil)
            image = content_tag :img, nil, src: file_url || image_url('upload'), data: { mime_match: 'image/*', replace: 'src' }
            video = content_tag :img, nil, src: image_url('video'), data: { mime_match: 'video/*' }
            file  = content_tag :img, nil, src: image_url('file'), data: { mime_match: '*/*' }
      
      
      Severity: Minor
      Found in app/inputs/action_admin/attachments_input.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 attachment_urls has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def attachment_urls
            media = nil
      
            if object.is_a? ::ActiveRecord::Base
              media = object.try(attribute_name)
      Severity: Minor
      Found in app/inputs/action_admin/attachments_input.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 attachment_multiple has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def attachment_multiple(file_url = nil, file_name = nil, file_path = nil, removable = false, media_type = nil)
      Severity: Minor
      Found in app/inputs/action_admin/upload_input.rb - About 35 mins to fix

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

            def attachment_preview(file_url = nil)
              data  = { src: 'file.preview.url', src_alt: 'file.url', url: "#{template.root_url.chomp('/')}[src]" }
              image = content_tag :img, nil, src: file_url, class: 'width-100', data: { mime_match: 'image/*', replace: 'src' }
              video = content_tag :video, nil, src: file_url, class: 'width-100', controls: true, data: { mime_match: 'video/*', replace: 'src' }
        
        
        Severity: Minor
        Found in app/inputs/action_admin/attachment_input.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 attachment_record has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def attachment_record
              medium = nil
        
              if object.is_a? ::ActiveRecord::Base
                medium = object.try(attribute_name)
        Severity: Minor
        Found in app/inputs/action_admin/attachment_input.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 attachment_multiple has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def attachment_multiple(file_url = nil, file_name = nil, file_path = nil, removable = false, media_type = nil)
              image = content_tag :img, nil, src: file_url || image_url('upload'), data: { mime_match: 'image/*', dz_thumbnail: '' }
              video = content_tag :img, nil, src: image_url('video'), data: { mime_match: 'video/*' }
              file  = content_tag :img, nil, src: image_url('file'), data: { mime_match: '*/*' }
              fname = content_tag :span, file_name, class: 'filename', data: { dz_name: '' }
        Severity: Minor
        Found in app/inputs/action_admin/upload_input.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 admin_shortcode_assets has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def admin_shortcode_assets
              assets = ActionAdmin.config.shortcode_assets.map do |asset|
                type = asset.split('.').last
                type == 'css' ? stylesheet_link_tag(asset) : javascript_include_tag(asset)
              end
        Severity: Minor
        Found in app/helpers/action_admin/admin_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

        Severity
        Category
        Status
        Source
        Language