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
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'),
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}")
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('_')
File notice.rb
has 320 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Notice < ApplicationRecord
include Searchability
include Elasticsearch::Model
extend RecentScope
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
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}")
- 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 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
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
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.'
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
- 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 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) {
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);
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>'
- 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 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]
- 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 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],
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,
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' }
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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' }
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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',