berkmancenter/lumendatabase

View on GitHub

Showing 47 of 47 total issues

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

      Method validate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate
          if @notice.nil?
            return {
              status: false,
              why: 'Notice not found.'
      Severity: Minor
      Found in app/controllers/token_urls_controller.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 included has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.included(model)
          model.instance_eval do
            to_validate = self.columns.select do |col|
              %i[string text].include?(col.type)
            end
      Severity: Minor
      Found in lib/validates_automatically.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 good_urls? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def good_urls?
          %i[url url_original].each do |attr|
            # URI::regexp will fail for things like "//bar.com", but we want to
            # allow those.
            value = self.send(attr)
      Severity: Minor
      Found in lib/validates_urls.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 create has a Cognitive Complexity of 7 (exceeds 5 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 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 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def new
          # Iframe session won't be kept so we need to use GET params
          flash.now[params[:flash_message]['type']] = params[:flash_message]['message'] if params[:flash_message]
      
          @display_models = Notice.display_models - [DataProtection]
      Severity: Minor
      Found in app/controllers/submitter_widget_notices_controller.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 set_all_entities has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_all_entities
          return unless !!user && !!(entity = user.entity)
      
          set_entity(:submitter, entity) unless entity_present?(:submitter)
          set_entity(:recipient, entity) unless entity_present?(:recipient)
      Severity: Minor
      Found in app/models/notice_builder.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 get_notice_type has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_notice_type(params)
          type_string = params[:type] || params[:notice][:type] || 'DMCA'
          type_string = 'DMCA' if type_string == 'Dmca'
      
          notice_type = type_string.classify.constantize
      Severity: Minor
      Found in app/controllers/notices_controller.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 index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          redirect_to root_path and return if params[:destination].nil?
      
          if params.dig('g-recaptcha-response-data', 'gateway')
            success_captcha = verify_recaptcha(action: 'gateway', minimum_score: 0.5)
      Severity: Minor
      Found in app/controllers/captcha_gateway_controller.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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          @new_token_params = token_url_params
      
          clean_up_email_address
      
      
      Severity: Minor
      Found in app/controllers/token_urls_controller.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

          { from: now - 1.year, to: now },
          { from: now - 5.years, to: now  },
          { from: now - 10.years, to: now },
          { from: now - 20.years, to: now }
      Severity: Minor
      Found in app/models/media_mention.rb and 1 other location - About 30 mins to fix
      app/models/elasticsearch/date_range_filter.rb on lines 47..50

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

      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

            { from: now - 1.day, to: now },
            { from: now - 1.month, to: now  },
            { from: now - 6.months, to: now },
            { from: now - 12.months, to: now },
      Severity: Minor
      Found in app/models/elasticsearch/date_range_filter.rb and 1 other location - About 30 mins to fix
      app/models/media_mention.rb on lines 18..21

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

      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

      Avoid too many return statements within this method.
      Open

            return {
              status: false,
              why: 'This IP address is not allowed. Try to use a different ' \
                   'IP address.'
            }
      Severity: Major
      Found in app/controllers/token_urls_controller.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return {
                status: false,
                why: 'This email address is not allowed. Try to use a different ' \
                     'email address.'
              }
        Severity: Major
        Found in app/controllers/token_urls_controller.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                return {
                  status: false,
                  why: 'This email address has been used already. Use a different ' \
                       'email, wait until the previous url expires or contact our ' \
                       'team at team@lumendatabase.org to get a researcher account.'
          Severity: Major
          Found in app/controllers/token_urls_controller.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                  return {
                    status: false,
                    why: 'Use a valid email address.'
                  }
            Severity: Major
            Found in app/controllers/token_urls_controller.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return
              Severity: Major
              Found in lib/yt_importer/yt_importer.rb - About 30 mins to fix

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

                      def parse_works
                        infringing_urls = parsed_infringing_urls.map do |url|
                          uri = URI.parse(url)
                          valid = %w(http https).include?(uri.scheme)
                          unless valid
                Severity: Minor
                Found in lib/yt_importer/mapping/base.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 default_kind_based_on_role has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def default_kind_based_on_role(role)
                    if role == 'issuing_court' ||
                       (role == 'principal' && @notice.class == LawEnforcementRequest) ||
                       (role == 'principal' && @notice.class == GovernmentRequest)
                      'organization'
                Severity: Minor
                Found in app/controllers/submitter_widget_notices_controller.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

                Severity
                Category
                Status
                Source
                Language