Showing 156 of 156 total issues
Method parse_fields
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def parse_fields(resource_klass, fields)
extracted_fields = {}
return extracted_fields if fields.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
Identical blocks of code found in 2 locations. Consider refactoring. Open
class BugTest < Minitest::Test
include Rack::Test::Methods
def json_api_headers
{'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
- 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 108.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
class BugTest < Minitest::Test
include Rack::Test::Methods
def json_api_headers
{'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
- 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 108.
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 verify_key
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def verify_key(key, context = nil)
key_type = resource_key_type
case key_type
when :integer
- 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 find_related_monomorphic_fragments
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def find_related_monomorphic_fragments(source_fragments, relationship, options, connect_source_identity)
filters = options.fetch(:filters, {})
source_ids = source_fragments.collect {|item| item.identity.id}
include_directives = options.fetch(:include_directives, {})
- 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 perform_joins
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def perform_joins(records, options)
join_array = flatten_join_tree_by_depth
join_array.each do |level_joins|
level_joins.each do |join_details|
- 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
Class Processor
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class Processor
include Callbacks
define_jsonapi_resources_callbacks :find,
:show,
:show_relationship,
Method attribute
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def attribute(attribute_name, options = {})
_clear_cached_attribute_options
_clear_fields_cache
attr = attribute_name.to_sym
- 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 find_fragments
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def find_fragments(filters, options = {})
include_directives = options.fetch(:include_directives, {})
resource_klass = self
fragments = {}
- 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
File acts_as_resource_controller.rb
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'csv'
module JSONAPI
module ActsAsResourceController
MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
Method verify_permitted_params
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def verify_permitted_params(params, allowed_fields)
formatted_allowed_fields = allowed_fields.collect { |field| format_key(field).to_sym }
params_not_allowed = []
params.each do |key, value|
Method update_links
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def update_links(serializer, result)
@top_level_links.merge!(result.links)
# Build pagination links
if result.is_a?(JSONAPI::ResourceSetOperationResult) ||
- 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 show_related_resources
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show_related_resources
source_klass = params[:source_klass]
source_id = params[:source_id]
relationship_type = params[:relationship_type]
filters = params[:filters]
Method add_resources_to_tree
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def add_resources_to_tree(resource_klass,
tree,
resources,
include_related,
source_rid: 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 jsonapi_resources
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def jsonapi_resources(*resources, &_block)
@resource_type = resources.first
res = JSONAPI::Resource.resource_klass_for(resource_type_with_module_prefix(@resource_type))
res._routed = true
Method parse_fields
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_fields(resource_klass, fields)
extracted_fields = {}
return extracted_fields if fields.nil?
Method relationships_hash
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def relationships_hash(source, fetchable_fields, relationship_data)
relationships = source.class._relationships.select{|k,_v| fetchable_fields.include?(k) }
field_set = supplying_relationship_fields(source.class) & relationships.keys
relationships.each_with_object({}) do |(name, relationship), hash|
- 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 jsonapi_links
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def jsonapi_links(*links)
link_type = links.first
formatted_relationship_name = format_route(link_type)
options = links.extract_options!.dup
- 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_pagination_params
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def parse_pagination_params(params)
if params.nil?
@offset = 0
@limit = JSONAPI.configuration.default_page_size
elsif params.is_a?(ActionController::Parameters)
- 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_pagination_params
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def parse_pagination_params(params)
if params.nil?
@number = 1
@size = JSONAPI.configuration.default_page_size
elsif params.is_a?(ActionController::Parameters)
- 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"