otwcode/otwarchive

View on GitHub
app/models/skin.rb

Summary

Maintainability
F
3 days
Test Coverage

File skin.rb has 473 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'fileutils'

class Skin < ApplicationRecord
  include HtmlCleaner
  include CssCleaner
Severity: Minor
Found in app/models/skin.rb - About 7 hrs to fix

    Class Skin has 49 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Skin < ApplicationRecord
      include HtmlCleaner
      include CssCleaner
      include SkinCacheHelper
      include SkinWizard
    Severity: Minor
    Found in app/models/skin.rb - About 6 hrs to fix

      Method load_site_css has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.load_site_css
          Skin.skin_dir_entries(Skin.site_skins_dir, /^\d+\.\d+$/).each do |version|
            version_dir = "#{Skin.site_skins_dir + version}/"
            if File.directory?(version_dir)
              # let's load up the file
      Severity: Minor
      Found in app/models/skin.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 load_site_css has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.load_site_css
          Skin.skin_dir_entries(Skin.site_skins_dir, /^\d+\.\d+$/).each do |version|
            version_dir = "#{Skin.site_skins_dir + version}/"
            if File.directory?(version_dir)
              # let's load up the file
      Severity: Major
      Found in app/models/skin.rb - About 2 hrs to fix

        Method get_style_block has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          def get_style_block(roles_to_include)
            block = ""
            if self.cached?
              # cached skin in a directory
              block = get_cached_style(roles_to_include)
        Severity: Minor
        Found in app/models/skin.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 cache! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def cache!
            self.clear_cache!
            self.public = true
            self.official = true
            save!
        Severity: Minor
        Found in app/models/skin.rb - About 1 hr to fix

          Method get_ie_comment has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_ie_comment(style, ie_condition = self.ie_condition)
              if ie_condition.present?
                ie_comment= "<!--[if "
                ie_comment += "lte " if ie_condition.match(/or_lower/)
                ie_comment += "gte " if ie_condition.match(/or_higher/)
          Severity: Minor
          Found in app/models/skin.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 get_wizard_settings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_wizard_settings
              style = ""
          
              style += font_size_styles(base_em) if base_em.present?
          
          
          Severity: Minor
          Found in app/models/skin.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 editable? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def editable?
              if self.filename.present?
                return false
              elsif self.official && self.public
                return true if User.current_user.is_a? Admin
          Severity: Minor
          Found in app/models/skin.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 cache! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def cache!
              self.clear_cache!
              self.public = true
              self.official = true
              save!
          Severity: Minor
          Found in app/models/skin.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 get_media_for_filename has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_media_for_filename
              ((media.nil? || media.empty?) ? DEFAULT_MEDIA : media).map {|m|
                case
                when m.match(/max-width: 42em/)
                  "narrow"
          Severity: Minor
          Found in app/models/skin.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

            has_attached_file :icon,
                              styles: { standard: "100x100>" },
                              url: "/system/:class/:attachment/:id/:style/:basename.:extension",
                              path: %w(staging production).include?(Rails.env) ? ":class/:attachment/:id/:style.:extension" : ":rails_root/public:url",
                              storage: %w(staging production).include?(Rails.env) ? :s3 : :filesystem,
          Severity: Minor
          Found in app/models/skin.rb and 1 other location - About 30 mins to fix
          app/models/collection.rb on lines 5..13

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

          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