Showing 22 of 22 total issues
Method update_values
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
def update_values
@checklist = Checklist.find params[:id]
@checklist.grade_callback = params[:checklist][:grade_callback]
@checklist.title = params[:checklist][:title]
@checklist.save
- 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 activateTable
has 164 lines of code (exceeds 25 allowed). Consider refactoring. Open
function activateTable() {
var table = $(this);
var container = table.parents('.topicContainer');
var topic_id = table.attr('id').replace('topic_','');
var min_text = table.find('.min');
Method yaml_to_topics
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def yaml_to_topics(yaml)
ordering = 1
topics = YAML.load(yaml).map do |thash|
thash = parse_ids_from :topic, thash
if thash.has_key? "id"
- 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 2 locations. Consider refactoring. Open
row.find('.deleteCheck').click(function() {
var id = row.find('.link_id').val();
if (id != "new") {
var deleteInput = $('<input type="hidden" name="deleted_topics_checks[]" />');
- 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 119.
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
container.find('.deleteTopic').click(function() {
var id = container.find('.topic_id').val();
if (id != "new") {
var deleteInput = $('<input type="hidden" name="deleted_topics[]" />');
- 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 119.
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 update_values
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_values
@checklist = Checklist.find params[:id]
@checklist.grade_callback = params[:checklist][:grade_callback]
@checklist.title = params[:checklist][:title]
@checklist.save
File checklists_controller.rb
has 309 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ChecklistsController < ApplicationController
def index
@checklists = Checklist.order :title
end
Function addTopics
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addTopics(checklist, topicData) {
$.each(topicData, function(topic_id,topic) {
var checks = {}
$.each(topic.checks, function(check_id,check) {
var element = $("#"+check_id);
Method topics_to_yaml
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def topics_to_yaml (topics)
StyledYAML.dump format_nice(topics.map{ |topic|
ret = topic.attributes.reject {|key,value|
%w(ordering checklist_id scoretype_id).include? key or value.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
Class Registration
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class Registration < ActiveRecord::Base
attr_accessible :repository, :topic, :active, :review1, :review2
belongs_to :course
belongs_to :user
Class User
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class User < ActiveRecord::Base
attr_accessible :email, :forename, :student_number, :surename, :password, :password_confirmation
has_secure_password
Method yaml_to_topics
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def yaml_to_topics(yaml)
ordering = 1
topics = YAML.load(yaml).map do |thash|
thash = parse_ids_from :topic, thash
if thash.has_key? "id"
Function autograding
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
$.fn.autograding = function(topicData) {
var feedbackContainer = $(this).find('.feedbacks');
var scoreContainer = $(this).find('.scores');
var initScores = getScoreInitializer(topicData.scoretypes);
var final_grade_callback = topicData.grade_callback;
Function autogrow
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
$.fn.autogrow = function(callback)
{
return this.filter('textarea').each(function()
{
var self = this;
Method prepare_based_on
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def prepare_based_on earlier_feedback, params
week_feedback = earlier_feedback
week_feedback.text += "\n-------------------\n" unless params[:week_feedback][:text].empty?
week_feedback.text += params[:week_feedback][:text] unless params[:week_feedback][:text].empty?
week_feedback.hidden_text = "" if week_feedback.hidden_text.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 toggle_review_participation
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def toggle_review_participation round
if round==1
self.participate_review1 = participate_review1 ? false : true
else
self.participate_review2 = participate_review2 ? false : true
- 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 calc
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function calc() {
var min = 0;
var max = 0;
for(var i=0; i<cells1.length; i++) {
var val1 = parseFloat(cells1[i].value,10);
Function activateRows
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function activateRows() {
table.find('tr:not(.activated)').each(function() {
var row = $(this);
row.addClass("activated");
row.find('.nametext').click(function() {
Method email
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def email(from, to, body, subject, cc, course="Ohjelmoinnin harjoitustyo")
Method scalar
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def scalar value, anchor, tag, plain, quoted, style