Noosfero/noosfero

View on GitHub
app/models/environment.rb

Summary

Maintainability
F
6 days
Test Coverage

Class Environment has 122 methods (exceeds 20 allowed). Consider refactoring.
Open

class Environment < ApplicationRecord
  attr_accessible :name, :is_default, :signup_welcome_text_subject,
                  :signup_welcome_text_body, :terms_of_use,
                  :message_for_disabled_enterprise, :news_amount_by_folder,
                  :default_language, :languages, :description,
Severity: Major
Found in app/models/environment.rb - About 2 days to fix

    File environment.rb has 885 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Environment < ApplicationRecord
      attr_accessible :name, :is_default, :signup_welcome_text_subject,
                      :signup_welcome_text_body, :terms_of_use,
                      :message_for_disabled_enterprise, :news_amount_by_folder,
                      :default_language, :languages, :description,
    Severity: Major
    Found in app/models/environment.rb - About 2 days to fix

      Method available_features has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.available_features
          {
            "disable_asset_articles" => _("Disable search for articles "),
            "disable_asset_enterprises" => _("Disable search for enterprises"),
            "disable_asset_people" => _("Disable search for people"),
      Severity: Minor
      Found in app/models/environment.rb - About 1 hr to fix

        Method create_templates has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create_templates
            prefix = self.name.to_slug + "_"
        
            enterprise_template = Enterprise.new(
              name: "Enterprise template",
        Severity: Minor
        Found in app/models/environment.rb - About 1 hr to fix

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

            def create_roles
              Role.create!(
                key: "environment_administrator",
                name: N_("Environment Administrator"),
                environment: self,
          Severity: Minor
          Found in app/models/environment.rb - About 1 hr to fix

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

              def default_hostname(email_hostname = false)
                domain = "localhost"
                domains = self.domains.order(:id)
                unless domains.empty?
                  domain = (domains.detect { |d| d.is_default } || domains.first).name
            Severity: Minor
            Found in app/models/environment.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 custom_person_fields= has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def custom_person_fields=(values)
                if values["schooling"] && values["schooling"]["active"] == "true"
                  schooling_status = values["schooling"]
                end
            
            
            Severity: Minor
            Found in app/models/environment.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 upload_quota_sizes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def upload_quota_sizes
                  quotas = metadata["quotas"] || {}
                  quotas.each do |klass, quota|
                    float_quota = Float(quota) rescue nil
                    if quota.present? && float_quota.nil?
            Severity: Minor
            Found in app/models/environment.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 custom_community_fields=(values)
                self.settings[:custom_community_fields] = values.delete_if { |key, value| !Community.fields.include?(key) }
                self.settings[:custom_community_fields].each_pair do |key, value|
                  if value["required"] == "true"
                    self.settings[:custom_community_fields][key]["active"] = "true"
            Severity: Major
            Found in app/models/environment.rb and 1 other location - About 1 hr to fix
            app/models/environment.rb on lines 610..618

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

            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 custom_enterprise_fields=(values)
                self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| !Enterprise.fields.include?(key) }
                self.settings[:custom_enterprise_fields].each_pair do |key, value|
                  if value["required"] == "true"
                    self.settings[:custom_enterprise_fields][key]["active"] = "true"
            Severity: Major
            Found in app/models/environment.rb and 1 other location - About 1 hr to fix
            app/models/environment.rb on lines 664..672

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

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

              def all_custom_enterprise_fields
                fields = self.settings[:custom_enterprise_fields].nil? ? {} : self.settings[:custom_enterprise_fields]
                self.enterprise_custom_fields.map do |cf|
                  fields[cf.name] = { "active" => cf.active.to_s, "required" => cf.required.to_s, "signup" => cf.signup.to_s }
                end
            Severity: Minor
            Found in app/models/environment.rb and 2 other locations - About 40 mins to fix
            app/models/environment.rb on lines 535..541
            app/models/environment.rb on lines 651..657

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

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

              def all_custom_person_fields
                fields = self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields]
                self.person_custom_fields.map do |cf|
                  fields[cf.name] = { "active" => cf.active.to_s, "required" => cf.required.to_s, "signup" => cf.signup.to_s }
                end
            Severity: Minor
            Found in app/models/environment.rb and 2 other locations - About 40 mins to fix
            app/models/environment.rb on lines 597..603
            app/models/environment.rb on lines 651..657

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

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

              def all_custom_community_fields
                fields = self.settings[:custom_community_fields].nil? ? {} : self.settings[:custom_community_fields]
                self.community_custom_fields.map do |cf|
                  fields[cf.name] = { "active" => cf.active.to_s, "required" => cf.required.to_s, "signup" => cf.signup.to_s }
                end
            Severity: Minor
            Found in app/models/environment.rb and 2 other locations - About 40 mins to fix
            app/models/environment.rb on lines 535..541
            app/models/environment.rb on lines 597..603

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

            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

              CAPTCHA_REQUIREMENTS = {
                suggest_article: { label: _("Suggest a new article"), options: Entitlement::Levels.range_options(0, 1) },
                forgot_password: { label: _("Recover forgotten password"), options: Entitlement::Levels.range_options(0, 1) },
                signup: { label: _("Sign up"), options: Entitlement::Levels.range_options(0, 1) },
            Severity: Minor
            Found in app/models/environment.rb and 1 other location - About 35 mins to fix
            app/models/profile.rb on lines 35..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 35.

            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 self.login_redirection_options
                {
                  "keep_on_same_page" => _("Stays on the same page the user was before login."),
                  "site_homepage" => _("Redirects the user to the environment homepage."),
                  "domain_root" => _("Redirects the user to the current domain root."),
            Severity: Minor
            Found in app/models/environment.rb and 1 other location - About 15 mins to fix
            app/models/environment.rb on lines 192..200

            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 self.signup_redirection_options
                {
                  "keep_on_same_page" => _("Stays on the same page the user was before signup."),
                  "site_homepage" => _("Redirects the user to the environment homepage."),
                  "domain_root" => _("Redirects the user to the current domain root."),
            Severity: Minor
            Found in app/models/environment.rb and 1 other location - About 15 mins to fix
            app/models/environment.rb on lines 179..187

            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