datacite/volpino

View on GitHub

Showing 45 of 65 total issues

Method load_index has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def load_index
      sort = case params[:sort]
             when "relevance" then { "_score" => { order: "desc" } }
             when "doi" then { "doi" => { order: "asc" } }
             when "-doi" then { "doi" => { order: "desc" } }
Severity: Minor
Found in app/controllers/admin/claims_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

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

function contributionsViz(json, sources) {
  data = json.contributions;

  json.href = "?page={{number}}";
  if (source_id !== "") { json.href += "&source_id=" + source_id; }
Severity: Minor
Found in app/assets/javascripts/works/index.js - About 1 hr to fix

    Method orcid_work_type has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def orcid_work_type(internal_work_type, internal_work_subtype)
          type =  case internal_work_type
                  when "Text"
                    case internal_work_subtype
                    when /^(Article|Articles|Journal Article|JournalArticle)$/i
    Severity: Minor
    Found in app/models/concerns/typeable.rb - About 1 hr to fix

      Method initialize has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def initialize(user)
          user ||= User.new(role_id: "anonymous") # Guest user
      
          if user.role_id == "staff_admin"
            can :manage, :all
      Severity: Minor
      Found in app/models/ability.rb - About 1 hr to fix

        Method load_index has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def load_index
              sort = case params[:sort]
                     when "relevance" then { "_score" => { order: "desc" } }
                     when "doi" then { "doi" => { order: "asc" } }
                     when "-doi" then { "doi" => { order: "desc" } }
        Severity: Minor
        Found in app/controllers/admin/claims_controller.rb - About 1 hr to fix

          Method process_data has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def process_data(options = {})
              start
          
              result = collect_data
          
          
          Severity: Minor
          Found in app/models/claim.rb - About 1 hr to fix

            Method globus has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def globus
                auth = request.env["omniauth.auth"]
            
                if current_user.present?
                  @user = current_user
            Severity: Minor
            Found in app/controllers/users/omniauth_callbacks_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 serialize_errors has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def serialize_errors(errors, options = {})
                  return nil if errors.nil?
            
                  errors_arr = []
            
            
            Severity: Minor
            Found in app/controllers/concerns/error_serializable.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 parse_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def parse_data(works, _options = {})
                Array(works).map do |work|
                  work.extend Hashie::Extensions::DeepFetch
                  doi = work.deep_fetch("external-ids", "external-id", 0, "external-id-value") { nil }
                  claimed_at = get_iso8601_from_epoch(work.deep_fetch("last-modified-date", "value") { nil })
            Severity: Minor
            Found in app/models/user.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 process_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def process_data(options = {})
                start
            
                result = collect_data
            
            
            Severity: Minor
            Found in app/models/claim.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 orcid_work_type has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def orcid_work_type(internal_work_type, internal_work_subtype)
                  type =  case internal_work_type
                          when "Text"
                            case internal_work_subtype
                            when /^(Article|Articles|Journal Article|JournalArticle)$/i
            Severity: Minor
            Found in app/models/concerns/typeable.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 create_index has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def create_index(options = {})
                  alias_name = options[:alias] || index_name
                  index_name = (options[:index] || self.index_name) + "_v1"
                  alternate_index_name = (options[:index] || self.index_name) + "_v2"
                  client = Elasticsearch::Model.client
            Severity: Minor
            Found in app/models/concerns/indexable.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def initialize(user)
                user ||= User.new(role_id: "anonymous") # Guest user
            
                if user.role_id == "staff_admin"
                  can :manage, :all
            Severity: Minor
            Found in app/models/ability.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
                @claim = Claim.where(orcid: params.fetch(:claim, {}).fetch(:orcid, nil),
                                     doi: params.fetch(:claim, {}).fetch(:doi, nil)).first
                exists = @claim.present?
            
            
            Severity: Minor
            Found in app/controllers/claims_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 decode_token has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def decode_token(token)
                  public_key = OpenSSL::PKey::RSA.new(ENV["JWT_PUBLIC_KEY"].to_s.gsub('\n', "\n"))
                  payload = (JWT.decode token, public_key, true, algorithm: "RS256").first
            
                  # check whether token has expired
            Severity: Minor
            Found in app/models/concerns/authenticable.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 delete_expired_token has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.delete_expired_token(index: nil)
                query = "orcid_expires_at:[1970-01-02 TO #{Date.today.strftime('%F')}]"
            
                response = User.query(query, index: index, page: { size: 1, cursor: [] })
                Rails.logger.info "#{response.results.total} Users with expired ORCID token found."
            Severity: Minor
            Found in app/models/user.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 parse_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.parse_data(items, options = {})
                if options[:id]
                  item = items.detect { |i| i["id"] == options[:id] }
                  return nil if item.nil?
            
            
            Severity: Minor
            Found in app/models/role.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 push_github_identifier has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def push_github_identifier(options = {})
                # user has not linked github username
                return OpenStruct.new(body: { "skip" => true }) unless github_to_be_created? || github_to_be_deleted?
            
                # missing data raise errors
            Severity: Minor
            Found in app/models/user.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

            Avoid too many return statements within this method.
            Open

                return OpenStruct.new(body: { "errors" => [{ "title" => "Missing data" }] }) if work.data.nil?
            Severity: Major
            Found in app/models/claim.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return OpenStruct.new(body: { "errors" => [{ "status" => 401, "title" => "token has expired." }] }) if (Date.new(1970, 1, 2).beginning_of_day..Date.today.end_of_day) === user.orcid_expires_at
              Severity: Major
              Found in app/models/claim.rb - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language