ministryofjustice/atet

View on GitHub

Showing 21 of 21 total issues

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

function enableOtherFieldsWhenAllowed() {
  privateFields.etIssueFeeEl().on('change keyup keypress', updateOtherFields);
  privateFields.etHearingFeeEl().on('change keyup keypress', updateOtherFields);
  privateFields.etReconsiderationFeeEl().on('change keyup keypress', updateOtherFields);
  privateFields.eatIssueFeeEl().on('change keyup keypress', updateOtherFields);
Severity: Major
Found in app/javascript/packs/pages/refunds/FeesPage.js and 1 other location - About 3 hrs to fix
app/javascript/packs/pages/refunds/FeesPage.js on lines 27..33

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

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 updateTotalFeesOnChange() {
  privateFields.etIssueFeeEl().on('change keyup keypress', updateTotalFees);
  privateFields.etHearingFeeEl().on('change keyup keypress', updateTotalFees);
  privateFields.etReconsiderationFeeEl().on('change keyup keypress', updateTotalFees);
  privateFields.eatIssueFeeEl().on('change keyup keypress', updateTotalFees);
Severity: Major
Found in app/javascript/packs/pages/refunds/FeesPage.js and 1 other location - About 3 hrs to fix
app/javascript/packs/pages/refunds/FeesPage.js on lines 19..25

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

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

Function exports has 78 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function(api) {
  var validEnv = ['development', 'test', 'production']
  var currentEnv = api.env()
  var isDevelopmentEnv = api.env('development')
  var isProductionEnv = api.env('production')
Severity: Major
Found in babel.config.js - About 3 hrs to fix

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

function setupReveal() {
  document.querySelectorAll('*[data-reveal-on-selector]').forEach(function (node) {
    const selector = node.attributes['data-reveal-on-selector'].value;
    const value = JSON.parse(node.attributes['data-reveal-on-value'].value);
    Components.RevealOnRadioButton(node, selector, value);
Severity: Major
Found in app/javascript/packs/pages/claims/ClaimTypePage.js and 1 other location - About 2 hrs to fix
app/javascript/packs/pages/claims/EmploymentPage.js on lines 3..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 92.

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

function setupReveal() {
  document.querySelectorAll('*[data-reveal-on-selector]').forEach(function (node) {
    const selector = node.attributes['data-reveal-on-selector'].value;
    const value = JSON.parse(node.attributes['data-reveal-on-value'].value);
    Components.RevealOnRadioButton(node, selector, value);
Severity: Major
Found in app/javascript/packs/pages/claims/EmploymentPage.js and 1 other location - About 2 hrs to fix
app/javascript/packs/pages/claims/ClaimTypePage.js on lines 3..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 92.

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

Function SessionPrompt has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const SessionPrompt = (function () {

  let settings = {
    SECOND: 1000
  };
Severity: Major
Found in app/javascript/packs/components/SessionPrompt.js - About 2 hrs to fix

Class FormCollectionProxy has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class FormCollectionProxy
  include Enumerable

  def initialize(child_form_class_name, collection_name, parent_form_instance)
    @parent_form_instance = parent_form_instance
Severity: Minor
Found in app/forms/form_collection_proxy.rb - About 2 hrs to fix

Method but_skip_postcode_validation has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.but_skip_postcode_validation
    Module.new do
      extend ActiveSupport::Concern

      const_set :ADDRESS_LINE_LENGTH, 50
Severity: Minor
Found in app/forms/address_attributes.rb - About 1 hr to fix

Function SessionPrompt has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const SessionPrompt = (function () {

  let settings = {
    SECOND: 1000
  };
Severity: Minor
Found in app/javascript/packs/components/SessionPrompt.js - 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 illegal_date? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def illegal_date?(record, attribute, value)
    # The date type in rails seems a bit basic in terms of validation - it will accept 31/2/xxxx but not 32/2/xxxx,
    #   neither of which should be valid so we are going to validate better here.
    raw_value = read_attribute_before_type_cast(record, attribute, default: nil)
    if raw_value.is_a?(String) && raw_value.blank?
Severity: Minor
Found in app/validators/date_validator.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 date_is_past? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def date_is_past?
    return if end_date.blank? || start_date.blank?
    return unless end_date.is_a?(Date) && start_date.is_a?(Date)

    errors.add(:start_date, :date_in_future) if Time.zone.today < start_date
Severity: Minor
Found in app/forms/employment_form.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 start_date_before_notice_period_end_date? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def start_date_before_notice_period_end_date?
    return if notice_period_end_date.blank? || start_date.blank?
    return unless notice_period_end_date.is_a?(Date) && start_date.is_a?(Date)

    return unless notice_period_end_date < start_date
Severity: Minor
Found in app/forms/employment_form.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 new_date has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def new_date(year, mon, mday = nil)
    mday ||= 1 if omit_day
    year = (1900 + year.to_i).to_s if allow_2_digit_year && year.present? && year.strip.length <= 2
    Date.strptime("#{year}-#{mon}-#{mday}", '%Y-%m-%d')
  rescue ::Date::Error, TypeError
Severity: Minor
Found in app/types/et_date_type.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 end_date_before_start_date? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def end_date_before_start_date?
    return if end_date.blank? || start_date.blank?
    return unless end_date.is_a?(Date) && start_date.is_a?(Date)

    return unless end_date < start_date
Severity: Minor
Found in app/forms/employment_form.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

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

  def update
    resource.assign_attributes params[current_step].permit!

    if params[:commit] == "claims.#{current_step}.add_fields"
      resource.secondary_claimants.build
Severity: Minor
Found in app/controllers/multiple_claimants_controller.rb and 1 other location - About 30 mins to fix
app/controllers/multiple_respondents_controller.rb on lines 6..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 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

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

  def update
    resource.assign_attributes params[current_step].permit!

    if params[:commit] == "claims.#{current_step}.add_fields"
      resource.secondary_respondents.build
Severity: Minor
Found in app/controllers/multiple_respondents_controller.rb and 1 other location - About 30 mins to fix
app/controllers/multiple_claimants_controller.rb on lines 6..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 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

Function monitorDownloadLink has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function monitorDownloadLink() {
  const successNode = document.querySelector('.pdf-success');
  const failureNode = document.querySelector('.pdf-failure');
  const url = successNode.getAttribute('href')
  let http = new XMLHttpRequest();
Severity: Minor
Found in app/javascript/packs/pages/claims/ClaimConfirmationPage.js - 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

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

  def illegal_year?(value)
    # Needs to verify that four digits are given for a year
    return false if value.nil?

    case value
Severity: Minor
Found in app/validators/date_validator.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

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

  def value_from_multiparameter_assignment(value)
    if value.is_a?(Hash)
      value = value.stringify_keys if value.respond_to?(:stringify_keys)
      begin
        super 1 => value['year'], 2 => value['month'], 3 => value['day']
Severity: Minor
Found in app/types/gds_date_type.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 end_date_before_start_date?
    return if end_date.blank? || start_date.blank?
    return unless end_date.is_a?(Date) && start_date.is_a?(Date)

    return unless end_date < start_date
Severity: Minor
Found in app/forms/employment_form.rb and 1 other location - About 20 mins to fix
app/forms/employment_form.rb on lines 107..113

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

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