omegainteractive/comfypress

View on GitHub
lib/comfypress/fixtures.rb

Summary

Maintainability
F
3 days
Test Coverage

Method import_layouts has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

  def self.import_layouts(to_site, from_folder = nil, path = nil, root = true, parent = nil, layout_ids = [], force_import = false)
    site = Cms::Site.find_or_create_by_identifier(to_site)
    unless path ||= find_fixtures_path((from_folder || to_site), 'layouts')
      ComfyPress.logger.warn('Cannot find Layout fixtures')
      return []
Severity: Minor
Found in lib/comfypress/fixtures.rb - About 5 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 import_pages has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

  def self.import_pages(to_site, from_folder = nil, path = nil, root = true, parent = nil, page_ids = [], force_import = false)
    site = Cms::Site.find_or_create_by_identifier(to_site)
    unless path ||= find_fixtures_path((from_folder || to_site), 'pages')
      ComfyPress.logger.warn('Cannot find Page fixtures')
      return []
Severity: Minor
Found in lib/comfypress/fixtures.rb - About 5 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 import_snippets has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def self.import_snippets(to_site, from_folder = nil, force_import = false)
    site = Cms::Site.find_or_create_by_identifier(to_site)
    unless path = find_fixtures_path((from_folder || to_site), 'snippets')
      ComfyPress.logger.warn('Cannot find Snippet fixtures')
      return []
Severity: Minor
Found in lib/comfypress/fixtures.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 import_pages has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.import_pages(to_site, from_folder = nil, path = nil, root = true, parent = nil, page_ids = [], force_import = false)
    site = Cms::Site.find_or_create_by_identifier(to_site)
    unless path ||= find_fixtures_path((from_folder || to_site), 'pages')
      ComfyPress.logger.warn('Cannot find Page fixtures')
      return []
Severity: Major
Found in lib/comfypress/fixtures.rb - About 2 hrs to fix

    Method import_layouts has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.import_layouts(to_site, from_folder = nil, path = nil, root = true, parent = nil, layout_ids = [], force_import = false)
        site = Cms::Site.find_or_create_by_identifier(to_site)
        unless path ||= find_fixtures_path((from_folder || to_site), 'layouts')
          ComfyPress.logger.warn('Cannot find Layout fixtures')
          return []
    Severity: Major
    Found in lib/comfypress/fixtures.rb - About 2 hrs to fix

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

        def self.export_pages(from_site, to_folder = nil)
          return unless site = Cms::Site.find_by_identifier(from_site)
          path = File.join(ComfyPress.config.fixtures_path, (to_folder || site.identifier), 'pages')
          FileUtils.rm_rf(path)
          FileUtils.mkdir_p(path)
      Severity: Minor
      Found in lib/comfypress/fixtures.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 import_snippets has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.import_snippets(to_site, from_folder = nil, force_import = false)
          site = Cms::Site.find_or_create_by_identifier(to_site)
          unless path = find_fixtures_path((from_folder || to_site), 'snippets')
            ComfyPress.logger.warn('Cannot find Snippet fixtures')
            return []
      Severity: Minor
      Found in lib/comfypress/fixtures.rb - About 1 hr to fix

        Method import_layouts has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def self.import_layouts(to_site, from_folder = nil, path = nil, root = true, parent = nil, layout_ids = [], force_import = false)
        Severity: Major
        Found in lib/comfypress/fixtures.rb - About 50 mins to fix

          Method import_pages has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def self.import_pages(to_site, from_folder = nil, path = nil, root = true, parent = nil, page_ids = [], force_import = false)
          Severity: Major
          Found in lib/comfypress/fixtures.rb - About 50 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    if page.new_record? || File.mtime(file_path) > page.updated_at || force_import
                      attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
                      page.label = attributes[:label] || slug.titleize
                      page.layout = site.layouts.find_by_identifier(attributes[:layout]) || parent.try(:layout)
                      page.target_page = site.pages.find_by_full_path(attributes[:target_page])
            Severity: Major
            Found in lib/comfypress/fixtures.rb - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                      if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
                        attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
                        layout.label      = attributes[:label] || identifier.titleize
                        layout.app_layout = attributes[:app_layout] || parent.try(:app_layout)
                        layout.position   = attributes[:position] if attributes[:position]
              Severity: Major
              Found in lib/comfypress/fixtures.rb - About 40 mins to fix

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

                      if File.exists?(file_path = File.join(path, 'js.js'))
                        if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
                          layout.js = File.open(file_path).read
                        end
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 3 other locations - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 40..43
                lib/comfypress/fixtures.rb on lines 45..48
                lib/comfypress/fixtures.rb on lines 183..186

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

                      if File.exists?(file_path = File.join(path, 'css.css'))
                        if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
                          layout.css = File.open(file_path).read
                        end
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 3 other locations - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 40..43
                lib/comfypress/fixtures.rb on lines 50..53
                lib/comfypress/fixtures.rb on lines 183..186

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

                      if File.exists?(file_path = File.join(path, 'content.html'))
                        if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
                          layout.content = File.open(file_path).read
                        end
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 3 other locations - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 45..48
                lib/comfypress/fixtures.rb on lines 50..53
                lib/comfypress/fixtures.rb on lines 183..186

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

                      if File.exists?(file_path = File.join(path, 'content.html'))
                        if snippet.new_record? || File.mtime(file_path) > snippet.updated_at || force_import
                          snippet.content = File.open(file_path).read
                        end
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 3 other locations - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 40..43
                lib/comfypress/fixtures.rb on lines 45..48
                lib/comfypress/fixtures.rb on lines 50..53

                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

                      if snippet.changed?
                        if snippet.save
                          ComfyPress.logger.warn("[Fixtures] Saved Snippet {#{snippet.identifier}}")
                        else
                          ComfyPress.logger.warn("[Fixtures] Failed to save Snippet {#{snippet.errors.inspect}}")
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 1 other location - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 58..64

                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

                      if layout.changed?
                        if layout.save
                          ComfyPress.logger.warn("[Fixtures] Saved Layout {#{layout.identifier}}")
                        else
                          ComfyPress.logger.error("[Fixtures] Failed to save Layout {#{layout.errors.inspect}}")
                Severity: Minor
                Found in lib/comfypress/fixtures.rb and 1 other location - About 15 mins to fix
                lib/comfypress/fixtures.rb on lines 190..196

                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