mysociety/alaveteli

View on GitHub

Showing 420 of 433 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  def subscribe_email_notice(track_thing)
    case track_thing.track_type
    when 'request_updates'
      _("You will now be emailed updates about '{{link_to_request}}', a request.",
        link_to_request: request_link(track_thing.info_request))
Severity: Major
Found in app/helpers/track_helper.rb and 2 other locations - About 1 hr to fix
app/helpers/track_helper.rb on lines 2..21
app/helpers/track_helper.rb on lines 78..97

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

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

Method update has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def update
    @pretoken_redirect = PostRedirect.find_by(token: @pretoken) if @pretoken

    if @password_change_user
      @password_change_user.password = params[:password_change_user][:password]
Severity: Minor
Found in app/controllers/password_changes_controller.rb - About 1 hr to fix

    Method remove_quoted_sections has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION")
        text = text.dup
        replacement = "\n" + replacement + "\n"
    
        # First do this peculiar form of quoting, as the > single line quoting
    Severity: Minor
    Found in app/models/incoming_message.rb - About 1 hr to fix

      Method alert_not_clarified_request has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.alert_not_clarified_request
          info_requests = InfoRequest.
                            where("awaiting_description = ?
                                   AND described_state = 'waiting_clarification'
                                   AND info_requests.updated_at < ?
      Severity: Minor
      Found in app/mailers/request_mailer.rb - About 1 hr to fix

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

          RefusalWizard.prototype._validQuestions = function() {
            var wizard = this;
        
            var dependents = wizard._dependents(wizard.$questions);
            wizard.log("VALID QUESTIONS:", dependents);
        Severity: Major
        Found in app/assets/javascripts/wizard.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/wizard.js on lines 197..203

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

        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

            $('.accordion-body').on('shown', function() {
              return $(this).prev().find('i.icon-chevron-right').first().removeClass().addClass('icon-chevron-down');
            });
        Severity: Major
        Found in app/assets/javascripts/admin/admin.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/admin/admin.js on lines 4..6

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

        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

          RefusalWizard.prototype._validSuggestions = function() {
            var wizard = this;
        
            var dependents = wizard._dependents(wizard.$suggestions);
            wizard.log("VALID SUGGESTIONS:", dependents);
        Severity: Major
        Found in app/assets/javascripts/wizard.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/wizard.js on lines 189..195

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

        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

            $('.accordion-body').on('hidden', function() {
              return $(this).prev().find('i.icon-chevron-down').first().removeClass().addClass('icon-chevron-right');
            });
        Severity: Major
        Found in app/assets/javascripts/admin/admin.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/admin/admin.js on lines 7..9

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

        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

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

          def hide
            ActiveRecord::Base.transaction do
              subject = params[:subject]
              explanation = params[:explanation]
        
        
        Severity: Minor
        Found in app/controllers/admin_request_controller.rb - About 1 hr to fix

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

            def assign_variables_for_show_template(info_request)
              @info_request = info_request
              @status = info_request.calculate_status
              @old_unclassified =
                info_request.is_old_unclassified? && authenticated?
          Severity: Minor
          Found in app/controllers/request_controller.rb - About 1 hr to fix

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

              DraftBatchSummary.startNewXHR = function startNewXHR() {
                if (DraftBatchSummary.currentXHR) {
                  DraftBatchSummary.currentXHR.abort();
                }
                $el.trigger(Events.loading);
            app/assets/javascripts/alaveteli_pro/batch_authority_search/initialise.js on lines 22..27

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

            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

              BatchAuthoritySearch.startNewXHR = function startNewXHR() {
                if (BatchAuthoritySearch.currentXHR) {
                  BatchAuthoritySearch.currentXHR.abort();
                }
                $el.trigger(Events.loading);
            app/assets/javascripts/alaveteli_pro/draft_batch_summary/initialise.js on lines 24..29

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

            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

            Method stop_new_responses_on_old_requests has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.stop_new_responses_on_old_requests
                # 'old' months since last change to request, only allow new incoming
                # messages from authority domains
                InfoRequest.
                  been_published.
            Severity: Minor
            Found in app/models/info_request.rb - About 1 hr to fix

              Method show has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def show
                  medium_cache
                  AlaveteliLocalization.with_locale(locale) do
                    # Test for whole request being hidden
                    return render_hidden if cannot?(:read, @info_request)
              Severity: Minor
              Found in app/controllers/request_controller.rb - About 1 hr to fix

                Method alert_new_response_reminders_internal has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def self.alert_new_response_reminders_internal(days_since, type_code)
                    info_requests = InfoRequest.
                      where_old_unclassified(days_since).
                        where(use_notifications: false).
                          order(:id).
                Severity: Minor
                Found in app/mailers/request_mailer.rb - About 1 hr to fix

                  Method other_country_message has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def other_country_message
                      flash.keep
                  
                      text = ""
                      site_country_code = AlaveteliConfiguration.iso_country_code.downcase
                  Severity: Minor
                  Found in app/controllers/services_controller.rb - About 1 hr to fix

                    Method create_request has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def create_request
                        json = ActiveSupport::JSON.decode(params[:request_json])
                        request = InfoRequest.new(
                          title: json["title"],
                          public_body_id: @public_body.id,
                    Severity: Minor
                    Found in app/controllers/api_controller.rb - About 1 hr to fix

                      Method calculate_last_event_forming_initial_request has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def calculate_last_event_forming_initial_request
                          # TODO: This can be removed when last_event_forming_initial_request_id has
                          # been populated for all requests
                      
                          expecting_clarification = false
                      Severity: Minor
                      Found in app/models/info_request.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 convert_image has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def convert_image
                          return if data.nil?
                          return if image.nil?
                      
                          # convert to PNG if it isn't, and to right size
                      Severity: Minor
                      Found in app/models/profile_photo.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 init_values has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.init_values(values)
                          values.each do |_method, index, prefix, value_type|
                            unless index.is_a? Integer
                              raise "Value index '#{index}' must be an Integer, is #{index.class}"
                            end
                      Severity: Minor
                      Found in lib/acts_as_xapian/acts_as_xapian.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

                      Severity
                      Category
                      Status
                      Source
                      Language