File request.rb
has 888 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "cgi"
require "multi_json"
require 'crack'
require 'crack/xml'
Method call
has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring. Open
def call(explicit_parameters=nil)
@instrumentation_name = "#{class_name}##{@method[:name]}"
result = nil
cached = nil
ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name, quiet: quiet?) do
- 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 handle_response
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
def handle_response(response, cached = nil)
@response = response
status = @response.status || 200
if @response.body.blank? && !@method[:options][:ignore_empty_response]
@response.response_headers['Content-Type'] = "application/json"
- 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 prepare_params
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
def prepare_params
if http_method == :post || http_method == :put || http_method == :patch
params = (@object._attributes rescue {}).merge(@params || {}) rescue {}
else
params = @params || @object._attributes rescue {}
- 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 do_request
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def do_request(etag)
http_headers = {}
http_headers["If-None-Match"] = etag if etag && !@method[:options][:skip_caching]
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
headers.each do |key,value|
- 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 generate_new_object
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def generate_new_object(options={})
if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
body = @response.body
elsif is_json_response?
begin
- 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 Request
has 47 methods (exceeds 20 allowed). Consider refactoring. Open
class Request
include AttributeParsing
include JsonAPIProxy
include ActiveSupport::Inflector
attr_accessor :post_params, :get_params, :url, :path, :headers, :method, :object, :body, :forced_url, :original_url, :retrying
Method prepare_request_body
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def prepare_request_body(params = nil)
if proxy == :json_api
if http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body])
@body = ""
else
- 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 set_corresponding_value
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def set_corresponding_value(value, key = nil, object = nil, overridden_name = nil)
optional_args = [key, object, overridden_name]
value_from_object = optional_args.all? # trying to parse a JSON Hash value
value_from_other_type = optional_args.none? # trying to parse anything else
raise Flexirest::InvalidArgumentsException.new("Optional args need all to be filled or none") unless value_from_object || value_from_other_type
- 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 call
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
def call(explicit_parameters=nil)
@instrumentation_name = "#{class_name}##{@method[:name]}"
result = nil
cached = nil
ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name, quiet: quiet?) do
Method do_request
has 83 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_request(etag)
http_headers = {}
http_headers["If-None-Match"] = etag if etag && !@method[:options][:skip_caching]
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
headers.each do |key,value|
Method prepare_params
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
def prepare_params
if http_method == :post || http_method == :put || http_method == :patch
params = (@object._attributes rescue {}).merge(@params || {}) rescue {}
else
params = @params || @object._attributes rescue {}
Method handle_response
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_response(response, cached = nil)
@response = response
status = @response.status || 200
if @response.body.blank? && !@method[:options][:ignore_empty_response]
@response.response_headers['Content-Type'] = "application/json"
Method prepare_request_body
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
def prepare_request_body(params = nil)
if proxy == :json_api
if http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body])
@body = ""
else
Method handle_hal_links_embedded
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def handle_hal_links_embedded(object, attributes)
attributes["_links"] = attributes[:_links] if attributes[:_links]
attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
if attributes["_links"]
attributes["_links"].each do |key, value|
- 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 generate_new_object
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_new_object(options={})
if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
body = @response.body
elsif is_json_response?
begin
Method prepare_url
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def prepare_url
missing = []
if @forced_url && @forced_url.present?
@url = @forced_url
else
- 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 set_corresponding_value
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_corresponding_value(value, key = nil, object = nil, overridden_name = nil)
optional_args = [key, object, overridden_name]
value_from_object = optional_args.all? # trying to parse a JSON Hash value
value_from_other_type = optional_args.none? # trying to parse anything else
raise Flexirest::InvalidArgumentsException.new("Optional args need all to be filled or none") unless value_from_object || value_from_other_type
Method new_object
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def new_object(attributes, name = nil, parent = nil, parent_attribute_name = nil)
@method[:options][:has_many] ||= {}
name = name.to_sym rescue nil
if @method[:options][:has_many][name]
parent_name = name
- 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 hal_response?
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def hal_response?
_, content_type = @response.response_headers.detect{|k,v| k.downcase == "content-type"}
faked_response = @response.response_headers.detect{|k,v| k.downcase == "x-arc-faked-response"}
if content_type && content_type.respond_to?(:each)
content_type.each do |ct|
- 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 handle_hal_links_embedded
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_hal_links_embedded(object, attributes)
attributes["_links"] = attributes[:_links] if attributes[:_links]
attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
if attributes["_links"]
attributes["_links"].each do |key, value|
Method new_object
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def new_object(attributes, name = nil, parent = nil, parent_attribute_name = nil)
@method[:options][:has_many] ||= {}
name = name.to_sym rescue nil
if @method[:options][:has_many][name]
parent_name = name
Avoid deeply nested control flow statements. Open
@body ||= if params.is_a?(String)
params
elsif @post_params.is_a?(String)
@post_params
else
Avoid deeply nested control flow statements. Open
if @object.changes.has_key? changed_attr.to_sym
newPostHash[changed_attr.to_sym] = @object[changed_attr.to_sym]
end
Avoid deeply nested control flow statements. Open
if wrap_root.present?
p = {wrap_root => p}
end
Avoid deeply nested control flow statements. Open
elsif request_body_type == :json
@body ||= if params.is_a?(String)
params
elsif @post_params.is_a?(String)
@post_params
Consider simplifying this complex logical expression. Open
if @forced_url && @forced_url.present?
@url = @forced_url
else
@url = @method[:url].dup
matches = @url.scan(/(:[a-z_-]+)/)
Avoid too many return
statements within this method. Open
return result if response.finished?
Avoid too many return
statements within this method. Open
return @response_delegate
Method api_auth_access_id
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def api_auth_access_id
ret = nil
if object_is_class?
ret = @object.api_auth_access_id
ret = ret.call if ret.respond_to?(:call)
- 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 username
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def username
ret = nil
if object_is_class?
ret = @object.username
ret = ret.call if ret.respond_to?(:call)
- 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 password
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def password
ret = nil
if object_is_class?
ret = @object.password
ret = ret.call if ret.respond_to?(:call)
- 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 api_auth_secret_key
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def api_auth_secret_key
ret = nil
if object_is_class?
ret = @object.api_auth_secret_key
ret = ret.call if ret.respond_to?(:call)
- 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
Similar blocks of code found in 4 locations. Consider refactoring. Open
def api_auth_access_id
ret = nil
if object_is_class?
ret = @object.api_auth_access_id
ret = ret.call if ret.respond_to?(:call)
- 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 31.
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 4 locations. Consider refactoring. Open
def password
ret = nil
if object_is_class?
ret = @object.password
ret = ret.call if ret.respond_to?(:call)
- 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 31.
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 4 locations. Consider refactoring. Open
def username
ret = nil
if object_is_class?
ret = @object.username
ret = ret.call if ret.respond_to?(:call)
- 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 31.
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 4 locations. Consider refactoring. Open
def api_auth_secret_key
ret = nil
if object_is_class?
ret = @object.api_auth_secret_key
ret = ret.call if ret.respond_to?(:call)
- 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 31.
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