unepwcmc/SAPI

View on GitHub

Showing 368 of 368 total issues

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

    var selection = $('#purposes'),
      args = {
        selection: selection,
        data: data.purposes,
        condition: function (item) {return item.code},
Severity: Major
Found in app/assets/javascripts/cites_trade/application.js and 2 other locations - About 3 hrs to fix
app/assets/javascripts/cites_trade/application.js on lines 333..341
app/assets/javascripts/cites_trade/application.js on lines 371..379

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

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

    var selection = $('#terms'),
      args = {
        selection: selection,
        data: data.terms,
        condition: function (item) {return item.code},
Severity: Major
Found in app/assets/javascripts/cites_trade/application.js and 2 other locations - About 3 hrs to fix
app/assets/javascripts/cites_trade/application.js on lines 371..379
app/assets/javascripts/cites_trade/application.js on lines 408..416

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

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

    var selection = $('#sources'),
      args = {
        selection: selection,
        data: data.sources,
        condition: function (item) {return item.code},
Severity: Major
Found in app/assets/javascripts/cites_trade/application.js and 2 other locations - About 3 hrs to fix
app/assets/javascripts/cites_trade/application.js on lines 333..341
app/assets/javascripts/cites_trade/application.js on lines 408..416

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

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

Class DocumentSearch has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

class DocumentSearch
  # NOTE!!! This class returns an unpaginated result. Not sure if pagination can be restored
  # and it is currently being done on the unpaginated query results in the API and web
  # documents #index endpoints.
  include CacheIterator
Severity: Minor
Found in app/services/document_search.rb - About 3 hrs to fix

    File compliance.rb has 296 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Trade::Grouping::Compliance < Trade::Grouping::Base
    
      # Complete up to current year - 1
      COUNTRIES = {
        2022 => 183,
    Severity: Minor
    Found in lib/modules/trade/grouping/compliance.rb - About 3 hrs to fix

      Class Output has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class NomenclatureChange::Output < ApplicationRecord
        include TrackWhoDoesIt
        attr_accessor :output_type # New taxon, Existing subspecies, Existing taxon
        # Migrated to controller (Strong Parameters)
        # attr_accessible :nomenclature_change_id, :taxon_concept_id,
      Severity: Minor
      Found in app/models/nomenclature_change/output.rb - About 3 hrs to fix

        Class MandatoryQuotasShipments has 26 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Trade::MandatoryQuotasShipments
          attr_reader :final_query
        
          QUOTAS_PATH = 'lib/data/quotas.csv'.freeze
        
        
        Severity: Minor
        Found in lib/modules/trade/mandatory_quotas_shipments.rb - About 3 hrs to fix

          Class ShowTaxonConceptSerializer has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class Species::ShowTaxonConceptSerializer < ActiveModel::Serializer
            cached
            root 'taxon_concept'
            attributes :id, :parent_id, :full_name, :author_year, :standard_references,
              :common_names, :distributions, :subspecies, :distribution_references,
          Severity: Minor
          Found in app/serializers/species/show_taxon_concept_serializer.rb - About 3 hrs to fix

            Method error_message has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              def error_message(values_hash = nil)
                scope_info = sanitized_sandbox_scope.map do |scope_column, scope_def|
                  tmp = []
                  if scope_def['inclusion']
                    tmp << "#{scope_column} = #{scope_def['inclusion'].join(', ')}"
            Severity: Minor
            Found in app/models/trade/inclusion_validation_rule.rb - About 2 hrs 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 copied_object_before_save has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              def copied_object_before_save(reassignment, reassignable)
                return nil if conflicting_listing_change_reassignment?(reassignment, reassignable)
                new_taxon_concept = @output.new_taxon_concept || @output.taxon_concept
            
                Rails.logger.debug("Processing #{reassignable.class} #{reassignable.id} copy to #{new_taxon_concept.full_name}")
            Severity: Minor
            Found in app/services/nomenclature_change/reassignment_copy_processor.rb - About 2 hrs 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 create_indexes_on_shipments has 71 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def self.create_indexes_on_shipments
                  sql = <<-SQL
                  CREATE INDEX index_trade_shipments_on_appendix
                    ON trade_shipments
                    USING btree
            Severity: Major
            Found in lib/modules/sapi_module/indexes.rb - About 2 hrs to fix

              Method raw_query has 70 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def raw_query(options)
                  "SELECT
                    shipments.id,
                    year,
                    appendix,
              Severity: Major
              Found in app/services/trade/shipment_report_queries.rb - About 2 hrs to fix

                Method index has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                Open

                  def index
                    if params[:taxon_concept_query].present?
                      exact_match = MTaxonConcept.where("LOWER(full_name) = ?", params[:taxon_concept_query].downcase)
                                                 .where(taxonomy_id: 1)
                                                 .first
                Severity: Minor
                Found in app/controllers/api/v1/documents_controller.rb - About 2 hrs 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 ar_klass has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def self.ar_klass(table_name)
                    klass_name = table_name.camelize
                    begin
                      "Trade::#{klass_name}".constantize
                    rescue NameError
                Severity: Major
                Found in app/models/trade/sandbox_template.rb - About 2 hrs to fix

                  Method run_final_queries has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def run_final_queries
                      # need to duplicate CoP documents, which are linked to more than one proposal
                      # that applies to old documents
                      sql = <<-SQL
                        WITH proposal_details AS (
                  Severity: Major
                  Found in lib/tasks/elibrary/citations_cop_importer.rb - About 2 hrs to fix

                    Method partial_db_query has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def self.partial_db_query(limit, offset, updated_at: nil, created_at: nil)
                        full_db_query(limit, offset) unless updated_at || created_at
                        where = if updated_at && !created_at
                                  "shipments.updated_at > '#{updated_at}'"
                                elsif created_at && !updated_at
                    Severity: Major
                    Found in app/services/trade/shipment_report_queries.rb - About 2 hrs to fix

                      Method cites_listing_changes has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def cites_listing_changes
                          rel = MCitesListingChange.from('api_cites_listing_changes_view AS listing_changes_mview').
                            where(
                              'listing_changes_mview.taxon_concept_id' => object_and_children
                            )
                      Severity: Major
                      Found in app/serializers/species/show_taxon_concept_serializer_cites.rb - About 2 hrs to fix

                        Method eu_listing_changes has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def eu_listing_changes
                            rel = MEuListingChange.from('api_eu_listing_changes_view AS listing_changes_mview').
                              where(
                                'listing_changes_mview.taxon_concept_id' => object_and_children
                              )
                        Severity: Major
                        Found in app/serializers/species/show_taxon_concept_serializer_cites.rb - About 2 hrs to fix

                          Method run_queries has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def run_queries
                              ApplicationRecord.connection.execute('DROP TABLE IF EXISTS elibrary_citations_resolved_tmp')
                              ApplicationRecord.connection.execute('CREATE TABLE elibrary_citations_resolved_tmp (document_id INT, CitationId INT, CtyISO2 TEXT, splus_taxon_concept_id INT)')
                              ApplicationRecord.connection.execute(
                                <<-SQL
                          Severity: Major
                          Found in lib/tasks/elibrary/citations_importer.rb - About 2 hrs to fix

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

                              def shipment_in_scope?(shipment)
                                shipment_in_scope = true
                                # check if shipment is in scope of this validation
                                sanitized_shipments_scope.each do |scope_column, scope_def|
                                  value = shipment.send(scope_column)
                            Severity: Minor
                            Found in app/models/trade/validation_rule.rb - About 2 hrs 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