discourse/discourse

View on GitHub
app/models/theme_field.rb

Summary

Maintainability
F
3 days
Test Coverage

File theme_field.rb has 425 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ThemeField < ActiveRecord::Base

  belongs_to :upload
  has_one :javascript_cache, dependent: :destroy

Severity: Minor
Found in app/models/theme_field.rb - About 6 hrs to fix

    Class ThemeField has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ThemeField < ActiveRecord::Base
    
      belongs_to :upload
      has_one :javascript_cache, dependent: :destroy
    
    
    Severity: Minor
    Found in app/models/theme_field.rb - About 3 hrs to fix

      Method process_html has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def process_html(html)
          errors = []
          javascript_cache || build_javascript_cache
      
          errors << I18n.t("themes.errors.optimized_link") if contains_optimized_link?(html)
      Severity: Minor
      Found in app/models/theme_field.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 ensure_baked! has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def ensure_baked!
          needs_baking = !self.value_baked || compiler_version != COMPILER_VERSION
          return unless needs_baking
      
          if basic_html_field? || translation_field?
      Severity: Minor
      Found in app/models/theme_field.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 validate_yaml! has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_yaml!
          return unless self.name == "yaml"
      
          errors = []
          begin
      Severity: Minor
      Found in app/models/theme_field.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 process_html has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def process_html(html)
          errors = []
          javascript_cache || build_javascript_cache
      
          errors << I18n.t("themes.errors.optimized_link") if contains_optimized_link?(html)
      Severity: Minor
      Found in app/models/theme_field.rb - About 1 hr to fix

        Method ensure_baked! has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def ensure_baked!
            needs_baking = !self.value_baked || compiler_version != COMPILER_VERSION
            return unless needs_baking
        
            if basic_html_field? || translation_field?
        Severity: Minor
        Found in app/models/theme_field.rb - About 1 hr to fix

          Method process_translation has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def process_translation
              errors = []
              javascript_cache || build_javascript_cache
              js_compiler = ThemeJavascriptCompiler.new(theme_id, self.theme.name)
              begin
          Severity: Minor
          Found in app/models/theme_field.rb - About 1 hr to fix

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

              def validate_yaml!
                return unless self.name == "yaml"
            
                errors = []
                begin
            Severity: Minor
            Found in app/models/theme_field.rb - About 1 hr to fix

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

                  def filename_from_opts(opts)
                    is_match = OPTIONS.all? do |option|
                      plural = :"#{option}s"
                      next true if @allowed_values[plural] == nil # Allows any value
                      next true if @allowed_values[plural].include?(opts[option]) # Value is allowed
              Severity: Minor
              Found in app/models/theme_field.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 ensure_scss_compiles! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def ensure_scss_compiles!
                  result = ["failed"]
                  begin
                    result = compile_scss
                    if contains_optimized_link?(self.value)
              Severity: Minor
              Found in app/models/theme_field.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 guess_type has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.guess_type(name:, target:)
                  if basic_targets.include?(target.to_s) && html_fields.include?(name.to_s)
                    types[:html]
                  elsif basic_targets.include?(target.to_s) && scss_fields.include?(name.to_s)
                    types[:scss]
              Severity: Minor
              Found in app/models/theme_field.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 opts_from_filename has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def opts_from_filename(filename)
                    match = @regex.match(filename)
                    return false unless match
                    hash = {}
                    OPTIONS.each do |option|
              Severity: Minor
              Found in app/models/theme_field.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 translation_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def translation_data(with_overrides: true, internal: false, fallback_fields: nil)
                  fallback_fields ||= theme.theme_fields.filter_locale_fields(I18n.fallbacks[name])
              
                  fallback_data = fallback_fields.each_with_index.map do |field, index|
                    begin
              Severity: Minor
              Found in app/models/theme_field.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

              There are no issues that match your filters.

              Category
              Status