sterrym/smithycms

View on GitHub

Showing 20 of 20 total issues

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

module Smithy
  class ImagesController < BaseController
    respond_to :html, :json

    def show
Severity: Major
Found in app/controllers/smithy/images_controller.rb and 1 other location - About 2 hrs to fix
app/controllers/smithy/contents_controller.rb on lines 3..38

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

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

module Smithy
  class ContentsController < BaseController
    respond_to :html, :json

    def show
Severity: Major
Found in app/controllers/smithy/contents_controller.rb and 1 other location - About 2 hrs to fix
app/controllers/smithy/images_controller.rb on lines 3..38

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

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

Class Page has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

      class Page < Base
        delegate :title, :depth, :permalink, :root, :site, :to => '_source'

        def breadcrumbs
          self._source.ancestors.where(["id != ?", root]).map(&:to_liquid)
Severity: Minor
Found in lib/smithy/liquid/drops/page.rb - About 2 hrs to fix

    Method initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            def initialize(tag_name, markup, tokens)
              @options = { :id => 'nav', :depth => 1, :class => '', :active_class => 'on', :include_root => false }
              if markup =~ Syntax
                @source = ($1 || 'site').gsub(/"|'/, '')
                markup.scan(::Liquid::TagAttributes) do |key, value|
    Severity: Minor
    Found in lib/smithy/liquid/tags/nav.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 pages has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def pages
          unless @pages
            return unless self.parent
            @pages = self.parent.children
            @pages = @pages.except(:order).order(sort_sql) unless sort_sql.nil?
    Severity: Minor
    Found in app/models/smithy/page_list.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 sanitize_config has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def sanitize_config
            {
              elements: %w(
                p div ul ol li blockquote pre h1 h2 h3 h4 h5 h6 object
                hr param
    Severity: Minor
    Found in lib/smithy/formatter.rb - About 1 hr to fix

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

          def create
            @page.duplicate_content_from(params[:page][:copy_content_from]) if params[:page][:copy_content_from].present? && @page.valid?
            @page.save
            flash.notice = "Your page was created #{@page.published? ? 'and published' : 'as a draft'}" if @page.persisted?
            respond_with @page do |format|
      Severity: Minor
      Found in app/controllers/smithy/pages_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

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

              class SmithyStylesheetLinkTag < Base
                def render(context)
                  controller = context.registers[:controller]
                  stylesheet = Smithy::Template.stylesheets.find_by(name: tag_without_ext('css'))
                  path = "/templates/stylesheets/#{tag_with_ext('css')}"
      Severity: Minor
      Found in lib/smithy/liquid/tags/html.rb and 1 other location - About 45 mins to fix
      lib/smithy/liquid/tags/html.rb on lines 46..52

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

      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 set_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def set_name
              if self.uploaded_file_url?
                self.name = File.basename(self.uploaded_file_url, '.*').titleize unless self.name?
              elsif self.file.present?
                self.name = File.basename(self.file_filename, '.*').titleize unless self.name?
      Severity: Minor
      Found in app/models/smithy/asset.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

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

              class SmithyJavascriptIncludeTag < Base
                def render(context)
                  controller = context.registers[:controller]
                  javascript = Smithy::Template.javascripts.find_by(name: tag_without_ext('js'))
                  path = "/templates/javascripts/#{tag_with_ext('js')}"
      Severity: Minor
      Found in lib/smithy/liquid/tags/html.rb and 1 other location - About 45 mins to fix
      lib/smithy/liquid/tags/html.rb on lines 55..61

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

      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 content_block_attributes_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def content_block_attributes_for(content_block_type)
              attributes_method = "#{content_block_type.underscore}_attributes".to_sym
              if self.respond_to?(attributes_method)
                public_send(attributes_method)
              else
      Severity: Minor
      Found in app/models/smithy/permitted_params.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 write_child_list_items? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

                def write_child_list_items?(parent, depth)
                  return false unless parent.present? && !parent.leaf?
                  return true if @source == 'site-section' && @page.self_and_ancestors.include?(parent)
                  depth > @options[:depth] ? false : true
                end
      Severity: Minor
      Found in lib/smithy/liquid/tags/nav.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 normalize_friendly_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def normalize_friendly_id(value) # normalize_friendly_id overrides the default creator for friendly_id
            return "/" if self.parent.blank?
            value = self.permalink? ? self.permalink.parameterize : value.to_s.parameterize
            [(self.parent.present? && !self.parent.root? ? self.parent.path : nil), value].join('/').downcase
          end
      Severity: Minor
      Found in app/models/smithy/page.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 register has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def register(content_block)
                return unless ActiveRecord::Base.connection.table_exists?(Smithy::ContentBlock.table_name)
                return unless ActiveRecord::Base.connection.table_exists?(content_block.table_name)
                content_block_name = content_block.to_s.demodulize
                @@content_blocks << content_block_name unless @@content_blocks.include?(content_block_name)
      Severity: Minor
      Found in lib/smithy/content_blocks/registry.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_list_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def render_list_item(item, depth)
                item_id = "#{@options[:id]}-#{item.permalink}"
                href = item.url
                label = item.title
                css_class = " class=\"#{@options[:active_class]}\"" if (@page && @page.id == item.id) || (@controller && [item.path, item.external_link].include?(@controller.request.path))
      Severity: Minor
      Found in lib/smithy/liquid/tags/nav.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 asset_preview_link has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def asset_preview_link(asset_id)
            asset = Smithy::Asset.find_by_id(asset_id)
            return unless asset
            link_to attachment_url(asset, :file) do
              if asset.file_type == :image
      Severity: Minor
      Found in app/helpers/smithy/assets_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 update
            @template = Template.find(params[:id])
            flash.notice = "Your template was saved" if @template.update_attributes(filtered_params)
            respond_with @template do |format|
              format.html { redirect_to [:edit, @template] }
      Severity: Minor
      Found in app/controllers/smithy/templates_controller.rb and 1 other location - About 15 mins to fix
      app/controllers/smithy/content_blocks_controller.rb on lines 31..35

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

      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
            @content_block = ContentBlock.find(params[:id])
            flash.notice = "Your content_block was saved" if @content_block.update_attributes(filtered_params)
            respond_with @content_block do |format|
              format.html { redirect_to [:edit, @content_block] }
      Severity: Minor
      Found in app/controllers/smithy/content_blocks_controller.rb and 1 other location - About 15 mins to fix
      app/controllers/smithy/templates_controller.rb on lines 40..44

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

      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 create
            @template = Template.new(filtered_params)
            @template.save
            flash.notice = "Your template was created" if @template.persisted?
            respond_with @template do |format|
      Severity: Minor
      Found in app/controllers/smithy/templates_controller.rb and 1 other location - About 15 mins to fix
      app/controllers/smithy/content_blocks_controller.rb on lines 17..22

      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

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

          def create
            @content_block = ContentBlock.new(filtered_params)
            @content_block.save
            flash.notice = "Your content_block was created" if @content_block.persisted?
            respond_with @content_block do |format|
      Severity: Minor
      Found in app/controllers/smithy/content_blocks_controller.rb and 1 other location - About 15 mins to fix
      app/controllers/smithy/templates_controller.rb on lines 18..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 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

      Severity
      Category
      Status
      Source
      Language