Showing 1,158 of 1,254 total issues
Method has too many lines. [17/10] Open
def sign_in
auth_server = SmartVillageApi.auth_server_url
uri = Addressable::URI.parse("#{auth_server}/users/sign_in.json")
result = ApiRequestService.new(uri.to_s, nil, nil, user_credentials).post_request
if result.code == "200" && result.body.present?
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Perceived complexity for index is too high. [14/7] Open
def index
if helpers.visible_in_role?("role_news_item")
news_results = @smart_village.query <<~GRAPHQL
query {
newsItems {
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for convert_params_for_graphql is too high. [13/6] Open
def convert_params_for_graphql
# Convert has_many categories
if @deadline_params["categories"].present?
categories = []
@deadline_params["categories"].each do |_key, category|
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method has too many lines. [17/10] Open
def tour_dates
@edit_year = (params[:year].presence || Date.today.year).to_i
@beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
@end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [17/10] Open
def determine_waste_locations
# Read from cache
# TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers
# if Rails.cache.exist?("waste_locations")
# @waste_locations = Rails.cache.read("waste_locations")
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [17/10] Open
def post_request
url = Addressable::URI.parse(@uri.strip).normalize
http = Net::HTTP.new(url.host, url.port || 80)
if @uri.include?("https://")
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Function setDefaultValues
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
var setDefaultValues = function (obj, schema, includeOptionalValues, skipFieldsWithoutDefaultValue) {
if (!obj || !schema) return obj;
if (!schema.properties) {
schema = { properties: schema };
}
Function getArrayBoundaries
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
formNode.prototype.getArrayBoundaries = function () {
var boundaries = {
minItems: -1,
maxItems: -1
};
Method edit
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
def edit
results = @smart_village.query <<~GRAPHQL
query {
genericItem(
id: #{params[:id]}
Complex method ApiRequestService#get_request (44.4) Open
def get_request(content_type_xml = false, pem = nil)
uri = Addressable::URI.parse(@uri.strip).normalize
uri.query = [uri.query, URI.encode_www_form(@params)].join("&") if @params&.any?
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method has too many lines. [16/10] Open
def edit_static_content_record
results = @smart_village.query <<~GRAPHQL
query {
staticContent: publicHtmlFile(
name: "#{params[:name]}",
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for create is too high. [21.56/15] Open
def create
query = create_params
begin
results = @smart_village.query query
rescue Graphlient::Errors::GraphQLError => e
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.
Method has too many lines. [16/10] Open
def create
unless category_present?(news_item_params)
flash[:error] = "Bitte eine Kategorie auswählen"
redirect_to new_news_item_path and return
end
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Perceived complexity for convert_params_for_graphql is too high. [13/7] Open
def convert_params_for_graphql
# Convert has_many categories
if @deadline_params["categories"].present?
categories = []
@deadline_params["categories"].each do |_key, category|
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Assignment Branch Condition size for create is too high. [21.75/15] Open
def create
unless category_present?(news_item_params)
flash[:error] = "Bitte eine Kategorie auswählen"
redirect_to new_news_item_path and return
end
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.
Method has too many lines. [16/10] Open
def convert_params_for_graphql
# Convert date, as we always have and need exactly one
if @survey_params["dates"].present?
dates = @survey_params.delete(:dates)
@survey_params["date"] = dates["0"]
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [16/10] Open
def edit_location
@edit_location_id = params[:location_id]
results = @smart_village.query <<~GRAPHQL
query {
wasteAddresses(
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Complex method SurveysController#edit_survey_record (44.4) Open
def edit_survey_record
results = @smart_village.query <<~GRAPHQL
query {
surveys(
ids: [
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Class WasteCalendarController
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class WasteCalendarController < ApplicationController
before_action :verify_current_user
before_action { verify_current_user_role("role_waste_calendar") }
before_action :init_graphql_client
before_action :determine_waste_types, only: %i[index new edit_tour edit_location tour_dates]
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (this.parentNode) {
this.arrayPath = _.clone(this.parentNode.arrayPath);
if (this.parentNode.view && this.parentNode.view.array) {
this.arrayPath.push(this.childPos);
}
- 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 81.
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