berkmancenter/lumendatabase

View on GitHub

Showing 36 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

                            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

                              Function keydown has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                , keydown: function (e) {
                                    var $this
                                      , $items
                                      , $active
                                      , $parent
                              Severity: Minor
                              Found in app/assets/javascripts/lumen/bootstrap-dropdown.js - About 1 hr to fix

                                Method approve_request has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  def approve_request
                                    new_entity = Entity.create!(
                                      name: self.entity_name,
                                      kind: self.entity_kind,
                                      address_line_1: self.entity_address_line_1,
                                Severity: Minor
                                Found in app/models/api_submitter_request.rb - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language