mysociety/alaveteli

View on GitHub

Showing 420 of 433 total issues

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

  def create
    begin
      @pro_account = current_user.pro_account ||= current_user.build_pro_account

      # Ensure previous incomplete subscriptions are cancelled to prevent them
Severity: Minor
Found in app/controllers/alaveteli_pro/subscriptions_controller.rb - About 1 hr to fix

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

      def update
        old_title = @info_request.title
        old_prominence = @info_request.prominence
        old_prominence_reason = @info_request.prominence_reason
        old_described_state = @info_request.described_state
    Severity: Minor
    Found in app/controllers/admin_request_controller.rb - About 1 hr to fix

      Method authorise has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def authorise
          @subscription = current_user.pro_account.subscriptions.
            retrieve(params.require(:id))
      
          if !@subscription
      Severity: Minor
      Found in app/controllers/alaveteli_pro/subscriptions_controller.rb - About 1 hr to fix

        Method excerpt has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def excerpt(text, phrase, options = {})
            return unless text && phrase
        
            separator = options.fetch(:separator, nil) || ""
            case phrase
        Severity: Minor
        Found in app/helpers/highlight_helper.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 download_entire_request has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def download_entire_request
            AlaveteliLocalization.with_locale(locale) do
              @info_request = InfoRequest.find_by_url_title!(params[:url_title])
              # Check for access and hide emargoed requests immediately, so that we
              # don't leak any info to people who can't access them
        Severity: Minor
        Found in app/controllers/request_controller.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 import_values_from_csv_row has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def import_values_from_csv_row(row, line, name, options)
            is_new = new_record?
            edit_info = if is_new
              { action: "creating new authority",
                comment: 'Created from spreadsheet' }
        Severity: Minor
        Found in app/models/public_body.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 display_status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def display_status
            if is_incoming_message?
              status = calculated_state
              return status.nil? ? _("Response") : InfoRequest.get_status_description(status)
            end
        Severity: Minor
        Found in app/models/info_request_event.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_terms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.init_terms(terms)
            terms.each do |_method, term_code, prefix|
              unless term_code.match(/^[A-Z]$/)
                raise "Use a single capital letter for term code"
              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

        Method body_request_events has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def body_request_events
            feed_type = params[:feed_type]
            if @public_body.id != params[:id].to_i
              raise PermissionDenied, "#{@public_body.id} != #{params[:id]}"
            end
        Severity: Minor
        Found in app/controllers/api_controller.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 words_to_highlight has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def words_to_highlight(opts = {})
              default_opts = { include_original: false, regex: false }
              opts = default_opts.merge(opts)
        
              # Reject all prefixes other than Z, which we know is reserved for stems
        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

        Method tnef_attachments has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def tnef_attachments(content)
            attachments = []
            Dir.mktmpdir do |dir|
              IO.popen("tnef -K -C #{dir} 2> /dev/null", "wb") do |f|
                f.write(content)
        Severity: Minor
        Found in lib/mail_handler.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 is_oof? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.is_oof?(message)
              # Check for out-of-office
        
              if MailHandler.get_header_string("X-POST-MessageClass", message) == "9; Autoresponder"
                return true
        Severity: Minor
        Found in lib/mail_handler/reply_handler.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 event_description has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def event_description(event)
            body_link = public_body_link_absolute(event.info_request.public_body)
            user_link = request_user_link_absolute(event.info_request)
            date = simple_date(event.created_at)
            case event.event_type
        Severity: Minor
        Found in app/helpers/application_helper.rb - About 1 hr to fix

          Method redeliver has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def redeliver
              message_ids = params[:url_title].split(',').map(&:strip)
              previous_request = @incoming_message.info_request
              destination_request = nil
          
          
          Severity: Minor
          Found in app/controllers/admin_incoming_message_controller.rb - About 1 hr to fix

            Method wall has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def wall
                long_cache
                @display_user = set_display_user
                @is_you = current_user_is_display_user
                feed_results = Set.new
            Severity: Minor
            Found in app/controllers/user_controller.rb - About 1 hr to fix

              Method signup has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def signup
                  # Make the user and try to save it
                  @user_signup = User.new(user_params(:user_signup))
                  error = false
                  if @request_from_foreign_country && !verify_recaptcha
              Severity: Minor
              Found in app/controllers/user_controller.rb - About 1 hr to fix

                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

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

                  $(function() {
                    $el = $('.js-draft-batch-request');
                    DraftBatchSummary.$el = $el;
                
                    $el.on(Events.loading, addLoadingClass);
                app/assets/javascripts/alaveteli_pro/batch_authority_search/initialise.js on lines 51..57

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

                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 already_subscribed_notice(track_thing)
                    case track_thing.track_type
                    when 'request_updates'
                      _("You are already subscribed to '{{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 25..44
                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

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

                  $(function() {
                    $el = $('.js-batch-authority-search');
                    BatchAuthoritySearch.$el = $el;
                
                    $el.on(Events.loading, addLoadingClass);
                app/assets/javascripts/alaveteli_pro/draft_batch_summary/initialise.js on lines 78..84

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

                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

                Severity
                Category
                Status
                Source
                Language