sharetribe/sharetribe

View on GitHub
app/controllers/admin/communities_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File communities_controller.rb has 296 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Admin::CommunitiesController < Admin::AdminBaseController
  include CommunitiesHelper

  before_action :ensure_white_label_plan, only: [:create_sender_address]

Severity: Minor
Found in app/controllers/admin/communities_controller.rb - About 3 hrs to fix

    Class CommunitiesController has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Admin::CommunitiesController < Admin::AdminBaseController
      include CommunitiesHelper
    
      before_action :ensure_white_label_plan, only: [:create_sender_address]
    
    
    Severity: Minor
    Found in app/controllers/admin/communities_controller.rb - About 2 hrs to fix

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

        def create_sender_address
          user_defined_address = EmailService::API::Api.addresses.get_user_defined(community_id: @current_community.id).data
      
          if user_defined_address && user_defined_address[:email] == params[:email].to_s.downcase.strip
            EmailService::API::Api.addresses.update(community_id: @current_community.id, id: user_defined_address[:id], name: params[:name])
      Severity: Minor
      Found in app/controllers/admin/communities_controller.rb - About 1 hr to fix

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

          def update_social_media
            @community = @current_community
            @selected_left_navi_link = "social_media"
        
            social_media_params = params.require(:community).permit(
        Severity: Minor
        Found in app/controllers/admin/communities_controller.rb - About 1 hr to fix

          Method update_look_and_feel has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update_look_and_feel
              @community = @current_community
              @selected_left_navi_link = "tribe_look_and_feel"
              analytic = AnalyticService::CommunityLookAndFeel.new(user: @current_user, community: @current_community)
          
          
          Severity: Minor
          Found in app/controllers/admin/communities_controller.rb - About 1 hr to fix

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

              def update_feature_flags(community_id:, person_id:, user_enabled:, user_disabled:, community_enabled:, community_disabled:)
                updates = []
                updates << -> {
                  FeatureFlagService::API::Api.features.enable(community_id: community_id, person_id: person_id, features: user_enabled)
                } unless user_enabled.blank?
            Severity: Minor
            Found in app/controllers/admin/communities_controller.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 update_look_and_feel has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def update_look_and_feel
                @community = @current_community
                @selected_left_navi_link = "tribe_look_and_feel"
                analytic = AnalyticService::CommunityLookAndFeel.new(user: @current_user, community: @current_community)
            
            
            Severity: Minor
            Found in app/controllers/admin/communities_controller.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 update has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def update(model, params, path, action, &block)
            Severity: Minor
            Found in app/controllers/admin/communities_controller.rb - About 35 mins to fix

              Method create_sender_address has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def create_sender_address
                  user_defined_address = EmailService::API::Api.addresses.get_user_defined(community_id: @current_community.id).data
              
                  if user_defined_address && user_defined_address[:email] == params[:email].to_s.downcase.strip
                    EmailService::API::Api.addresses.update(community_id: @current_community.id, id: user_defined_address[:id], name: params[:name])
              Severity: Minor
              Found in app/controllers/admin/communities_controller.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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def update_feature_flags(community_id:, person_id:, user_enabled:, user_disabled:, community_enabled:, community_disabled:)
                  updates = []
                  updates << -> {
                    FeatureFlagService::API::Api.features.enable(community_id: community_id, person_id: person_id, features: user_enabled)
                  } unless user_enabled.blank?
              Severity: Major
              Found in app/controllers/admin/communities_controller.rb and 1 other location - About 2 hrs to fix
              app/controllers/admin2/advanced/experimental_controller.rb on lines 49..71

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

              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

                    error_message =
                      case Maybe(res.data)[:error_code]
                      when Some(:invalid_email)
                        t("admin.communities.outgoing_email.invalid_email_error", email: res.data[:email])
                      when Some(:invalid_email_address)
              Severity: Major
              Found in app/controllers/admin/communities_controller.rb and 1 other location - About 1 hr to fix
              app/controllers/admin2/emails/outgoing_emails_controller.rb on lines 56..66

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

              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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def check_email_status
                  res = EmailService::API::Api.addresses.get_user_defined(community_id: @current_community.id)
              
                  if res.success
                    address = res.data
              Severity: Minor
              Found in app/controllers/admin/communities_controller.rb and 1 other location - About 1 hr to fix
              app/controllers/admin2/emails/outgoing_emails_controller.rb on lines 75..88

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

              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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def find_or_initialize_customizations
                  @current_community.locales.each do |locale|
                    next if @current_community.community_customizations.find_by_locale(locale)
              
                    @current_community.community_customizations.create(
              Severity: Minor
              Found in app/controllers/admin/communities_controller.rb and 1 other location - About 30 mins to fix
              app/controllers/admin/community_seo_settings_controller.rb on lines 31..40

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

              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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def enqueue_status_sync!(address)
                  Maybe(address)
                    .reject { |addr| addr[:verification_status] == :verified }
                    .each { |addr|
                    EmailService::API::Api.addresses.enqueue_status_sync(
              Severity: Minor
              Found in app/controllers/admin/communities_controller.rb and 1 other location - About 25 mins to fix
              app/controllers/admin2/emails/outgoing_emails_controller.rb on lines 98..104

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

              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