discourse/discourse

View on GitHub
lib/site_setting_extension.rb

Summary

Maintainability
D
2 days
Test Coverage

File site_setting_extension.rb has 424 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'site_settings/deprecated_settings'
require_dependency 'site_settings/type_supervisor'
require_dependency 'site_settings/defaults_provider'
require_dependency 'site_settings/db_provider'

Severity: Minor
Found in lib/site_setting_extension.rb - About 6 hrs to fix

    Method setting has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      def setting(name_arg, default = nil, opts = {})
        name = name_arg.to_sym
    
        if name == :default_locale
          raise Discourse::InvalidParameters.new("Other settings depend on default locale, you can not configure it like this")
    Severity: Minor
    Found in lib/site_setting_extension.rb - About 3 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 setup_methods has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def setup_methods(name)
        clean_name = name.to_s.sub("?", "").to_sym
    
        if type_supervisor.get_type(name) == :upload
          define_singleton_method clean_name do
    Severity: Minor
    Found in lib/site_setting_extension.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 setting has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def setting(name_arg, default = nil, opts = {})
        name = name_arg.to_sym
    
        if name == :default_locale
          raise Discourse::InvalidParameters.new("Other settings depend on default locale, you can not configure it like this")
    Severity: Minor
    Found in lib/site_setting_extension.rb - About 1 hr to fix

      Method all_settings has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def all_settings(include_hidden = false)
      
          locale_setting_hash =
          {
            setting: 'default_locale',
      Severity: Minor
      Found in lib/site_setting_extension.rb - About 1 hr to fix

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

          def setup_methods(name)
            clean_name = name.to_s.sub("?", "").to_sym
        
            if type_supervisor.get_type(name) == :upload
              define_singleton_method clean_name do
        Severity: Minor
        Found in lib/site_setting_extension.rb - About 1 hr to fix

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

            def set(name, value, options = nil)
              if has_setting?(name)
                value = filter_value(name, value)
                if options
                  self.public_send("#{name}=", value, options)
          Severity: Minor
          Found in lib/site_setting_extension.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 ensure_listen_for_changes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def ensure_listen_for_changes
              return if @listen_for_changes == false
          
              unless @subscribed
                MessageBus.subscribe("/site_settings") do |message|
          Severity: Minor
          Found in lib/site_setting_extension.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 diff_hash has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def diff_hash(new_hash, old)
              changes = []
              deletions = []
          
              new_hash.each do |name, value|
          Severity: Minor
          Found in lib/site_setting_extension.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

          There are no issues that match your filters.

          Category
          Status