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" } }
- Read upRead up
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; }
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
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
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" } }
Method process_data
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_data(options = {})
start
result = collect_data
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 = []
- Read upRead up
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 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
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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 })
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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?
- Read upRead up
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
- Read upRead up
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."
- Read upRead up
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?
- Read upRead up
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
- Read upRead up
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" => work.validation_errors.map { |error| { "title" => error } } }) if work.validation_errors.present?
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