sanger/sequencescape

View on GitHub

Showing 5,431 of 5,433 total issues

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

      if params[:role]
        authorizable_object =
          if params[:role][:authorizable_type] == 'project'
            Project.find(params[:role][:authorizable_id])
          else
Severity: Major
Found in app/controllers/admin/users_controller.rb and 1 other location - About 1 hr to fix
app/controllers/admin/users_controller.rb on lines 48..64

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

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 progress_report_on_all_assets has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def progress_report_on_all_assets # rubocop:todo Metrics/AbcSize
    yield(progress_report_header)

    each_stock_well_id_in_study_in_batches do |asset_ids|
      # eager loading of well_attribute , can only be done on  wells ...
Severity: Minor
Found in app/models/study_report/study_details.rb - About 1 hr to fix

    Complex method AccessionService#accession_submission_xml (37.5)
    Open

      def accession_submission_xml(submission, accession_number) # rubocop:todo Metrics/AbcSize
        xml = Builder::XmlMarkup.new
        xml.instruct!
        xml.SUBMISSION(
          'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    Severity: Minor
    Found in app/models/accession_service.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Robot::Verification::Base#validate_barcode_params (37.4)
    Open

      def validate_barcode_params(barcode_hash) # rubocop:todo Metrics/CyclomaticComplexity
        return yield('No barcodes specified') if barcode_hash.nil?
    
        if barcode_hash[:batch_barcode].blank? || !Batch.valid_barcode?(barcode_hash[:batch_barcode])
          yield('Worksheet barcode invalid')
    Severity: Minor
    Found in app/models/robot/verification/base.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Ability::BaseUser#grant_privileges (37.4)
    Open

      def grant_privileges # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
        Rails.logger.debug { 'Granting BaseUser privileges' }
    
        can :delete, Comment, { user_id: user.id }
        can :create, Comment, commentable_type: %w[Study Sample], commentable: { owners: { id: user.id } }
    Severity: Minor
    Found in app/models/ability/base_user.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method SamplesController#create (37.4)
    Open

      def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
        @sample = Sample.new(params[:sample])
    
        study_id = params[:study_id]
        if study_id
    Severity: Minor
    Found in app/controllers/samples_controller.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Tasks::PlateTransferHandler#find_or_create_target (37.4)
    Open

      def find_or_create_target(task) # rubocop:todo Metrics/AbcSize
        return target_plate if target_plate.present?
    
        # We only eager load the request stuff if we actually need it.
        batch_requests = @batch.requests.includes(includes_for_plate_creation)

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Submission::AssetSubmissionFinder#find_wells_including_samples_for! (37.3)
    Open

      def find_wells_including_samples_for!(details) # rubocop:todo Metrics/AbcSize
        barcodes, well_list = details['barcode'], details['plate well']
        errors.add(:spreadsheet, 'You can only specify one plate per asset group') unless barcodes.uniq.one?
        barcode = barcodes.first
        plate = Plate.find_from_barcode(barcode)

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Accessionable::Sample#xml (37.2)
    Open

        def xml # rubocop:todo Metrics/AbcSize
          xml = Builder::XmlMarkup.new
          xml.instruct!
          xml.SAMPLE_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do
            xml.SAMPLE(sample_element_attributes) do
    Severity: Minor
    Found in app/models/accessionable/sample.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Transfer::State::TubeState::included (37.2)
    Open

        def self.included(base) # rubocop:todo Metrics/MethodLength
          base.class_eval do
            scope :in_state,
                  lambda { |states|
                    states = Array(states).map(&:to_s)
    Severity: Minor
    Found in app/models/transfer/state.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Method perform_pick has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def perform_pick(requests, robot, control_source_plate, workflow_controller) # rubocop:todo Metrics/AbcSize
        max_plates = robot.max_beds
        raise StandardError, 'The chosen robot has no beds!' if max_plates.zero?
    
        destination_plates = []
    Severity: Minor
    Found in app/models/cherrypick_task.rb - About 1 hr to fix

      Method render_class_for_model has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def render_class_for_model(model) # rubocop:todo Metrics/CyclomaticComplexity
            render_class = Class.new(self)
      
            # NOTE: It's quite annoying that you don't have any access to the inheritable class attributes from
            # within the Class.new block above, so we have to do a separate instance_eval to get it to work.
      Severity: Minor
      Found in app/models/api/base.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 record_tube_samples has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def record_tube_samples # rubocop:todo Metrics/AbcSize
              tube_counter = 0
              first_to_last.each do |sheet_row|
                row = dynamic_attributes[sheet_row]
                build_tube_sample_manifest_asset do |sample_manifest_asset|

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

        def generate_picking_data_hash(target_barcode, requests: requests_for_destination_plate)
          data_objects = {}
          source_barcode_to_pick_number = {}
      
          current_pick_size = lambda { data_objects[data_objects.size]['source'].size }
      Severity: Minor
      Found in app/models/robot/pick_data.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

      Complex method AssetsController#show (36.9)
      Open

        def show # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
          # LEGACY API FOR CGP to allow switch-over
          # In future they will use the recpetacles/:id/parent
          if request.format.xml?
            @asset = Receptacle.include_for_show.find(params[:id])
      Severity: Minor
      Found in app/controllers/assets_controller.rb by flog

      Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

      You can read more about ABC metrics or the flog tool

      Method process has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def process # rubocop:todo Metrics/CyclomaticComplexity
          # Store the details of the successful submissions so the user can be presented with a summary
          @submission_ids = []
          @completed_submissions = {}
      
      
      Severity: Minor
      Found in app/models/bulk_submission.rb - About 1 hr to fix

        Method create_request_chain! has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create_request_chain!(request_type_and_multiplier_pairs, source_data_set, multiplexing_assets, &block) # rubocop:todo Metrics/CyclomaticComplexity
            raise StandardError, 'No request types specified!' if request_type_and_multiplier_pairs.empty?
        
            request_type, multiplier = request_type_and_multiplier_pairs.shift
        
        
        Severity: Minor
        Found in app/models/submission/linear_request_graph.rb - About 1 hr to fix

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

          const select_all = function () {
            var scope = this.dataset.scope || "body";
            // find all the enabled, unchecked checkboxes and select them
            // fire the change event on them, to allow other js code to pick up that they have changed
            $(scope).find('input[type="checkbox"]:enabled:not(:checked)').prop("checked", true).trigger("change");
          Severity: Major
          Found in app/frontend/legacy/sequencescape.js and 1 other location - About 1 hr to fix
          app/frontend/legacy/sequencescape.js on lines 18..23

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

          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

          const deselect_all = function () {
            var scope = this.dataset.scope || "body";
            // find all the enabled, checked checkboxes and deselect them
            // fire the change event on them, to allow other js code to pick up that they have changed
            $(scope).find('input[type="checkbox"]:enabled:checked').prop("checked", false).trigger("change");
          Severity: Major
          Found in app/frontend/legacy/sequencescape.js and 1 other location - About 1 hr to fix
          app/frontend/legacy/sequencescape.js on lines 11..16

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

          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

          Complex method RequestClassDeprecator#deprecate_class (36.2)
          Open

            def deprecate_class(request_class_name, options = {}) # rubocop:todo Metrics/AbcSize
              state_changes = options.fetch(:state_change, {})
              new_request_type = options.fetch(:new_type, transfer_request)
              new_class_name = new_request_type.request_class_name
          
          
          Severity: Minor
          Found in lib/request_class_deprecator.rb by flog

          Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

          You can read more about ABC metrics or the flog tool

          Severity
          Category
          Status
          Source
          Language