Showing 278 of 278 total issues
Class Exercise
has 66 methods (exceeds 20 allowed). Consider refactoring. Open
class Exercise < ApplicationRecord
self.include_root_in_json = false
include Swagger::Blocks
swagger_schema :ExerciseWithPoints do
Method initialize
has 223 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(user)
if user.administrator?
can :manage, :all
can :create, Course
can :create, :custom_course
Consider simplifying this complex logical expression. Open
if user.administrator?
can :manage, :all
can :create, Course
can :create, :custom_course
cannot :refresh, Course
File course.rb
has 471 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'gdocs_export'
require 'system_commands'
require 'date_and_time_utils'
class Course < ApplicationRecord
Class Course
has 51 methods (exceeds 20 allowed). Consider refactoring. Open
class Course < ApplicationRecord
include SystemCommands
include Swagger::Blocks
swagger_schema :Course do
Class Submission
has 43 methods (exceeds 20 allowed). Consider refactoring. Open
class Submission < ApplicationRecord
include Swagger::Blocks
swagger_schema :Submission do
key :required, %i[id user_id pretest_error created_at exercise_name course_id processed
File exercise.rb
has 404 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'shellwords'
require 'date_and_time_utils'
class Exercise < ApplicationRecord
Class User
has 42 methods (exceeds 20 allowed). Consider refactoring. Open
class User < ApplicationRecord
include Comparable
include Gravtastic
include Swagger::Blocks
gravtastic
Method create
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def create
if !params[:submission] || !params[:submission][:file]
return respond_not_found('No ZIP file selected or failed to receive it')
end
- 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 send_submission
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def send_submission(submission, notify_url)
exercise = submission.exercise
raise 'Submission has no secret token' if submission.secret_token.blank?
raise "Exercise #{submission.exercise_name} for submission gone. Cannot resubmit." if exercise.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 email_confirmation
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def email_confirmation(user, origin = nil, language = nil)
@origin = origin
@user = user
token = user.verification_tokens.email.create!
@url = confirm_email_url(@user.id, token.token, language: language)
- 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 check_access!
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def check_access!
if current_user.guest?
raise CanCan::AccessDenied
end
- 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 30 (exceeds 5 allowed). Consider refactoring. Open
def show
@course ||= @submission.course
@exercise ||= @submission.exercise
@organization = @course.organization
- 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 29 (exceeds 5 allowed). Consider refactoring. Open
def create
unauthorize_guest!
@exercise = Exercise.find(params[:exercise_id])
authorize! :read, @exercise
- 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
File submission.rb
has 338 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'zlib'
require 'securerandom'
require 'submission_packager'
class Submission < ApplicationRecord
Method update
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def update
authorize! :teach, @organization
print_setup_phases(3)
- 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
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
- 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 137.
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
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
- 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 137.
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 initialize
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def initialize(user)
if user.administrator?
can :manage, :all
can :create, Course
can :create, :custom_course
- 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 24 (exceeds 5 allowed). Consider refactoring. Open
def show
@submission = Submission.find_by!(id: params[:id])
unless @submission.processed?
authorization_skip!
sandbox_status = :created
- 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"