berkmancenter/lumendatabase

View on GitHub

Showing 47 of 47 total issues

Class Notice has 52 methods (exceeds 20 allowed). Consider refactoring.
Open

class Notice < ApplicationRecord
  include Searchability
  include Elasticsearch::Model

  extend RecentScope
Severity: Major
Found in app/models/notice.rb - About 7 hrs to fix

    Method all has 113 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.all
        [
          Language.new('af', 'Afrikaans'),
          Language.new('am', 'Amharic'),
          Language.new('ar', 'Arabic'),
    Severity: Major
    Found in lib/language.rb - About 4 hrs to fix

      Method import_single_notice has 97 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def import_single_notice(file_to_process)
            @logger.info("Importing --- #{@number_imported + @number_failed_imports}/#{@number_to_import} --- file")
            @logger.info("Importing #{file_to_process}")
      
            if system("grep -q '<table' #{file_to_process}")
      Severity: Major
      Found in lib/yt_importer/yt_importer.rb - About 3 hrs to fix

        Method define_elasticsearch_mapping has 95 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def define_elasticsearch_mapping(exclusions = {})
              index_name [Rails.application.engine_name,
                          Rails.env,
                          'notice',
                          ENV['ES_INDEX_SUFFIX']].compact.join('_')
        Severity: Major
        Found in app/models/elasticsearch/searchability.rb - About 3 hrs to fix

          File notice.rb has 320 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          class Notice < ApplicationRecord
            include Searchability
            include Elasticsearch::Model
          
            extend RecentScope
          Severity: Minor
          Found in app/models/notice.rb - About 3 hrs to fix

            Class Base has 30 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class Base
                  def initialize(notice_text, raw_file_path)
                    @notice_text = notice_text
                    @raw_file_path = raw_file_path
                    @notice_type = DMCA
            Severity: Minor
            Found in lib/yt_importer/mapping/base.rb - About 3 hrs to fix

              Method import_single_notice has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
              Open

                  def import_single_notice(file_to_process)
                    @logger.info("Importing --- #{@number_imported + @number_failed_imports}/#{@number_to_import} --- file")
                    @logger.info("Importing #{file_to_process}")
              
                    if system("grep -q '<table' #{file_to_process}")
              Severity: Minor
              Found in lib/yt_importer/yt_importer.rb - About 3 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 initialize has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def initialize(user)
                  # anonymous user
                  can :request_access_token, Notice do |notice|
                    !notice&.submitter&.full_notice_only_researchers
                  end
              Severity: Major
              Found in app/models/ability.rb - About 2 hrs to fix

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

                class NoticesController < ApplicationController
                  layout :resolve_layout
                  protect_from_forgery with: :exception
                  skip_before_action :verify_authenticity_token, only: :create
                
                
                Severity: Minor
                Found in app/controllers/notices_controller.rb - About 2 hrs to fix

                  Method validate has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def validate
                      if @notice.nil?
                        return {
                          status: false,
                          why: 'Notice not found.'
                  Severity: Major
                  Found in app/controllers/token_urls_controller.rb - About 2 hrs to fix

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

                      def initialize(user)
                        # anonymous user
                        can :request_access_token, Notice do |notice|
                          !notice&.submitter&.full_notice_only_researchers
                        end
                    Severity: Minor
                    Found in app/models/ability.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

                    Function prefilledInput has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      $.fn.prefilledInput = function() {
                    
                        var focus = function () {
                          $(this).removeClass('prefilled');
                          if (this.value == this.prefilledValue) {
                    Severity: Minor
                    Found in app/assets/javascripts/lumen/prefilled_input.js - About 1 hr to fix

                      Function cookie has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          var config = $.cookie = function (key, value, options) {
                      
                              // write
                              if (value !== undefined) {
                                  options = $.extend({}, config.defaults, options);
                      Severity: Minor
                      Found in app/assets/javascripts/lumen/jquery.cookie.js - About 1 hr to fix

                        Method json_to_html has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def json_to_html(hash)
                            output = '<ul>'
                        
                            hash.each do |key, value|
                              output += '<li>'
                        Severity: Minor
                        Found in app/mailers/submitter_widget_mailer.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 index has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def index
                            if request.format.html? && current_user.nil? && !Rails.env.test?
                              permitted = false
                        
                              if session[:captcha_permission]
                        Severity: Minor
                        Found in app/controllers/search_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 notice_for_email has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def notice_for_email(notice)
                            entities_fields = %w[name kind address_line_1 address_line_2 state country_code phone email url city zip]
                        
                            notice.as_json(
                              only: %w[id title body created_at subject language jurisdictions tags type mark_registration_number],
                        Severity: Minor
                        Found in app/mailers/submitter_widget_mailer.rb - About 1 hr to fix

                          Method notice_params has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def notice_params
                              raw_params = params.require(:notice).except(:type).permit(
                                :title,
                                :subject,
                                :body,
                          Severity: Minor
                          Found in app/controllers/notices_controller.rb - About 1 hr to fix

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

                            module RailsAdmin
                              module Config
                                module Actions
                                  class RejectApiSubmitterRequest < Base
                                    register_instance_option(:only) { 'ApiSubmitterRequest' }
                            lib/rails_admin/config/actions/approve_api_submitter_request.rb on lines 12..30

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

                            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

                            module RailsAdmin
                              module Config
                                module Actions
                                  class ApproveApiSubmitterRequest < Base
                                    register_instance_option(:only) { 'ApiSubmitterRequest' }
                            lib/rails_admin/config/actions/reject_api_submitter_request.rb on lines 12..30

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

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

                              def create
                                unless authorized_to_create?
                                  Rails.logger.warn "Could not auth user with params: #{params}"
                                  redirect_to_new_form({
                                    type: 'alert',
                            Severity: Minor
                            Found in app/controllers/submitter_widget_notices_controller.rb - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language