Showing 1,158 of 1,254 total issues
Function computeInitialValues
has 162 lines of code (exceeds 25 allowed). Consider refactoring. Open
formNode.prototype.computeInitialValues = function (values, ignoreDefaultValues) {
var self = this;
var node = null;
var nbChildren = 1;
var i = 0;
Method has too many lines. [51/10] Open
def convert_params_for_graphql
# Convert has_many contacts
if @job_params["contacts"].present?
contacts = []
@job_params["contacts"].each do |_key, contact|
- 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 edit
has 159 lines of code (exceeds 25 allowed). Consider refactoring. Open
def edit
results = @smart_village.query <<~GRAPHQL
query {
eventRecord(
id: #{params[:id]}
Cyclomatic complexity for convert_params_for_graphql is too high. [46/6] Open
def convert_params_for_graphql
# Check recursively if any addresses data is given.
# If not, we do not want to submit the params, because the name is required by the model,
# which will result in a validation error.
if @tour_params["addresses"].present?
- 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.
Function split
has 153 lines of code (exceeds 25 allowed). Consider refactoring. Open
var split = function (jsonform, keys, options) {
options = options || {};
keys = keys || [];
if (!jsonform || !jsonform.form) {
return {
Method convert_params_for_graphql
has 152 lines of code (exceeds 25 allowed). Consider refactoring. Open
def convert_params_for_graphql
# Check recursively if any addresses data is given.
# If not, we do not want to submit the params, because the name is required by the model,
# which will result in a validation error.
if @tour_params["addresses"].present?
Method has too many lines. [46/10] Open
def edit
results = @smart_village.query <<~GRAPHQL
query {
genericItem(
id: #{params[:id]}
- 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 DashboardController#index (85.0) Open
def index
if helpers.visible_in_role?("role_news_item")
news_results = @smart_village.query <<~GRAPHQL
query {
newsItems {
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
'onInsert': function (evt, node) {
$(node.el).find('a._jsonform-delete').on('click', function (evt) {
$(node.el).find('._jsonform-preview').remove();
$(node.el).find('a._jsonform-delete').remove();
$(node.el).find('#' + escapeSelector(node.id)).val('');
- 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 150.
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
'onInsert': function (evt, node) {
$(node.el).find('a._jsonform-delete').on('click', function (evt) {
$(node.el).find('._jsonform-preview').remove();
$(node.el).find('a._jsonform-delete').remove();
$(node.el).find('#' + escapeSelector(node.id)).val('');
- 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 150.
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 convert_params_for_graphql
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. 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
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
Assignment Branch Condition size for convert_params_for_graphql is too high. [50.26/15] Open
def convert_params_for_graphql
# Convert has_many content_blocks(which has_many media_contents)
content_block_params = @offer_params["content_blocks"]
return unless content_block_params.present?
- 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.
File tours_controller.rb
has 406 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ToursController < ApplicationController
before_action :verify_current_user
before_action { verify_current_user_role("role_tour") }
before_action :init_graphql_client
before_action :load_category_list, only: [:edit, :new, :create]
Complex method JobsController#convert_params_for_graphql (84.8) Open
def convert_params_for_graphql
# Convert has_many contacts
if @job_params["contacts"].present?
contacts = []
@job_params["contacts"].each do |_key, contact|
- 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. [43/10] Open
def index
results = @smart_village.query <<~GRAPHQL
query {
genericItems(genericType: "DefectReport") {
id
- 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. [42/10] Open
def set_defaults_and_types(entry)
# set default values
entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
if entry.keys.include?("temperature")
- 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. [42/10] Open
def convert_params_for_graphql
# Convert has_many content_blocks(which has_many media_contents)
content_block_params = @offer_params["content_blocks"]
return unless content_block_params.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.
Method index
has 130 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
if helpers.visible_in_role?("role_news_item")
news_results = @smart_village.query <<~GRAPHQL
query {
newsItems {
Method has too many lines. [40/10] Open
def create
results = @smart_village.query <<~GRAPHQL
query {
publicJsonFile(name: "wasteTypes", version: "1.0.0") {
content
- 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 ToursController#set_defaults_and_types (77.4) Open
def set_defaults_and_types(entry)
# set default values
entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
if entry.keys.include?("temperature")
- 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