mysociety/alaveteli

View on GitHub

Showing 328 of 434 total issues

Method data_and_draft_checks has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def data_and_draft_checks
    if data.nil?
      errors.add(:data, _("Please choose a file containing your photo."))
      return
    end
Severity: Minor
Found in app/models/profile_photo.rb - About 55 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 get_previous_email_sent_to has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def get_previous_email_sent_to(info_request_event)
    last_email = nil
    info_request_events.each do |e|
      if ((info_request_event.is_sent_sort? && e.is_sent_sort?) || (info_request_event.is_followup_sort? && e.is_followup_sort?)) && e.outgoing_message_id == info_request_event.outgoing_message_id
        break if e.id == info_request_event.id
Severity: Minor
Found in app/models/info_request.rb - About 55 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 body has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def body
    return @cached_body if @cached_body

    begin
      return file.download if masked?
Severity: Minor
Found in app/models/foi_attachment.rb - About 55 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 confirm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def confirm
    post_redirect = PostRedirect.find_by_email_token(params[:email_token])

    if post_redirect.nil? || !post_redirect.email_token_valid?
      render template: 'user/bad_token'
Severity: Minor
Found in app/controllers/users/confirmations_controller.rb - About 55 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 authorise has a Cognitive Complexity of 9 (exceeds 5 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 55 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 contact has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def contact
    # if they clicked remove for link to request/body, remove it
    if params[:remove]
      @last_request = nil
      cookies['last_request_id'] = nil
Severity: Minor
Found in app/controllers/help_controller.rb - About 55 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 mass_tag has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def mass_tag
    lookup_query

    if params[:tag] && (params[:tag] != "")
      if params[:table_name] == 'exact'
Severity: Minor
Found in app/controllers/admin_public_body_controller.rb - About 55 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 signchangeemail has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def signchangeemail
    # "authenticated?" has done the redirect to signin page for us
    return unless authenticated? || ask_to_login(
      web: _('To change your email address used on {{site_name}}',
             site_name: site_name),
Severity: Minor
Found in app/controllers/user_controller.rb - About 55 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

  var disableButton = function disableButton() {
    if ($draft.find(authorityInListSelector).length === 0) {
      $writeButton.prop('disabled', true);
    }
  };
app/assets/javascripts/alaveteli_pro/draft_batch_summary/write-button.js on lines 13..17

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

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

  var enableButton = function enableButton() {
    if ($draft.find(authorityInListSelector).length > 0) {
      $writeButton.prop('disabled', false);
    }
  };
app/assets/javascripts/alaveteli_pro/draft_batch_summary/write-button.js on lines 20..24

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

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

  describe ".accept?" do
    subject { ExcelAnalyzer::XlsAnalyzer.accept?(blob) }

    context "when the blob is an Excel file" do
      let(:blob) { fake_blob(content_type: "application/vnd.ms-excel") }
Severity: Minor
Found in gems/excel_analyzer/spec/excel_analyzer/xls_analyzer_spec.rb and 1 other location - About 55 mins to fix
gems/excel_analyzer/spec/excel_analyzer/eml_analyzer_spec.rb on lines 7..17

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

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

  describe ".accept?" do
    subject { ExcelAnalyzer::EmlAnalyzer.accept?(blob) }

    context "when the blob is an email" do
      let(:blob) { fake_blob(content_type: "message/rfc822") }
Severity: Minor
Found in gems/excel_analyzer/spec/excel_analyzer/eml_analyzer_spec.rb and 1 other location - About 55 mins to fix
gems/excel_analyzer/spec/excel_analyzer/xls_analyzer_spec.rb on lines 7..17

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

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 set_described_state has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def set_described_state(new_state, set_by = nil, message = "")
    old_described_state = described_state
    ActiveRecord::Base.transaction do
      self.awaiting_description = false
      last_event = info_request_events.last
Severity: Minor
Found in app/models/info_request.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 import_csv has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def self.import_csv(csv, tag, tag_behaviour, dry_run, editor, available_locales = [])
Severity: Minor
Found in app/models/public_body.rb - About 45 mins to fix

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

      def valid_to_reply_to?
        email = from_email.try(:downcase)
    
        # check validity of email
        return false if email.nil? || !MySociety::Validate.is_valid_email(email)
    Severity: Minor
    Found in app/models/raw_email.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 populate_from_ical_feed has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def populate_from_ical_feed
        cal_file = open(ical_feed_url)
        cal_parser = Icalendar::Parser.new(cal_file)
        cals = cal_parser.parse
        cal = cals.first
    Severity: Minor
    Found in app/models/holiday_import.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 import_csv_from_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = [])
    Severity: Minor
    Found in app/models/public_body.rb - About 45 mins to fix

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

        def unmasked_body
          MailHandler.attachment_body_for_hexdigest(
            raw_email.mail,
            hexdigest: hexdigest
          )
      Severity: Minor
      Found in app/models/foi_attachment.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 explorable_in_datasette? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def explorable_in_datasette?(attachment)
          return false unless attachment.is_public?
          return false unless attachment.incoming_message.is_public?
          return false unless info_request_is_public?(attachment)
          return false unless attachment.content_type == 'text/csv'
      Severity: Minor
      Found in app/helpers/datasette_helper.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 with_query has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.with_query(query, tag)
          like_query = "%#{query}%"
          has_first_letter = tag.size == 1
      
          underscore_locale = AlaveteliLocalization.locale
      Severity: Minor
      Found in app/models/public_body.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

      Severity
      Category
      Status
      Source
      Language