Showing 278 of 278 total issues
Method course_stats_show_submissions
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def course_stats_show_submissions
return respond_not_found('No submissions yet') if @course.submissions.empty?
@start_time =
if params[:start_time]
- 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 update
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def update
authorize! :update, @user
User.transaction do
@email_before = @user.email
- 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 for_submission
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def self.for_submission(submission)
Dir.mktmpdir do |tmpdir|
zip_path = "#{tmpdir}/submission.zip"
File.open(zip_path, 'wb') { |f| f.write(submission.return_file) }
SafeUnzipper.new.unzip(zip_path, tmpdir)
- 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 assign_show_view_vars
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def assign_show_view_vars
@exercises = @course.exercises.includes(:course)
@exercises.preload(:unlocks).where(unlocks: { user: current_user })
@exercises = @exercises.select { |ex| ex.visible_to?(current_user) }
.natsort_by(&: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 refresh_course
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def refresh_course(course, data)
@report = Report.new
@rust_data = data['output-data']
Course.transaction(requires_new: true) do
@course = Course.find(course.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
Method load_fields
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.load_fields(kind, config_file_path)
return [] unless File.exist?(config_file_path)
kind = kind.to_s
Identical blocks of code found in 2 locations. Consider refactoring. Open
swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/users/{user_id}/points' do
operation :get do
key :description, "Returns the given user's points from the course in a json format. Course is searched by name"
key :produces, ['application/json']
key :tags, ['point']
- 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 58.
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
swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/users/{user_id}/points' do
operation :get do
key :description, "Returns the given user's points from the course in a json format. Course is searched by name"
key :produces, ['application/json']
key :tags, ['point']
- 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 58.
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 check_access!
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def check_access!
if current_user.guest?
raise CanCan::AccessDenied
end
Method index
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
if params[:course_id]
fetch :course
@organization = @course.organization
@my_reviews = @course.submissions
Method submission_review_column
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def submission_review_column(submission)
if submission.reviewed?
if can? :create_review, submission.course
link_to 'Available', new_submission_review_path(submission)
else
Method index
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
@course = Course.find(params[:course_id])
authorize! :see_points, @course
return respond_unauthorized('Authentication required') if current_user.guest?
add_course_breadcrumb
Method course_data
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def course_data(organization, course, opts = {})
@course = course
data = {
id: course.id,
name: course.name,
Method create
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
return respond_forbidden unless current_user.administrator?
users = if params[:extra_fields]
User.eager_load(:user_field_values).where(login: params[:usernames])
else
Method create
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
return respond_forbidden unless current_user.administrator?
users = if params[:extra_fields]
User.eager_load(:user_field_values).where(id: params[:ids])
else
Method exercise_data
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def exercise_data(exercise)
return nil unless exercise.visible_to?(@user)
# optimization: use @unlocked_exercises to avoid querying unlocks repeatedly
locked = exercise.requires_unlock? && !@unlocked_exercises.include?(exercise.name)
Method run
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def run
return unless @kafka_bridge_url && @kafka_bridge_secret && @service_id
return if @kafka_bridge_url.empty? || @kafka_bridge_secret.empty? || @service_id.empty?
KafkaBatchUpdatePoints.where(realtime: true).each do |task|
finished_successfully = false
- 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
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def show
if params[:username].present? && params[:session_id].present?
user = User.find_by(login: params[:username])
user ||= User.find_by('lower(email) = ?', params[:username].downcase)
# Allows using oauth2 tokens of the new api for authenticating
- 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 print_setup_phases
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def print_setup_phases(phase = 0)
update_setup_phase(phase) unless phase == 2
maxphase = setup_in_progress? ? session[:ongoing_course_setup][:phase] : phase
STEPS.each_with_index do |st, i|
path = 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 create
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def create
authorize! :teach, @organization
custom = params[:course][:course_template_id].blank?
- 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"