epicodus/epicenter

View on GitHub

Showing 53 of 53 total issues

Class Student has 86 methods (exceeds 20 allowed). Consider refactoring.
Open

class Student < User
  scope :with_activated_accounts, -> { where('sign_in_count > ?', 0 ) }

  validate :primary_payment_method_belongs_to_student

Severity: Major
Found in app/models/student.rb - About 1 day to fix

    File student.rb has 475 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Student < User
      scope :with_activated_accounts, -> { where('sign_in_count > ?', 0 ) }
    
      validate :primary_payment_method_belongs_to_student
    
    
    Severity: Minor
    Found in app/models/student.rb - About 7 hrs to fix

      Class Course has 48 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Course < ApplicationRecord
        default_scope { order(:start_date) }
      
        scope :fulltime_courses, -> { where(parttime: false) }
        scope :parttime_intro_courses, -> { joins(:track).where("tracks.description IN (?)", ['Part-Time Intro to Programming', 'Part-Time Evening Intro to Programming']) }
      Severity: Minor
      Found in app/models/course.rb - About 6 hrs to fix

        Method update_student_as_admin has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_student_as_admin
            @student = Student.find(params[:id])
            if @student.update(student_params)
              if student_params[:cohort_id]
                redirect_to student_courses_path(@student), notice: "Current cohort for #{@student.name} has been set to #{@student.cohort.try(:description) || 'blank'}."
        Severity: Minor
        Found in app/controllers/students_controller.rb - About 4 hrs to fix

        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 CrmLead has 30 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class CrmLead
          def initialize(email)
            @email = email
          end
        
        
        Severity: Minor
        Found in app/models/crm_lead.rb - About 3 hrs to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            $('#student_probation_advisor').change(function() {
              var prompt = this.checked ? 'Are you sure you want to put this student on Academic Warning (ADVISOR)?' : 'Remove student from Academic Warning (ADVISOR)?'
              var confirmed = confirm(prompt);
              if (confirmed) {
                this.form.submit();
          Severity: Major
          Found in app/assets/javascripts/probation.js and 1 other location - About 3 hrs to fix
          app/assets/javascripts/probation.js on lines 2..10

          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 103.

          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

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            $('#student_probation_teacher').change(function() {
              var prompt = this.checked ? 'Are you sure you want to put this student on Academic Warning (TEACHER)?' : 'Remove student from Academic Warning (TEACHER)?'
              var confirmed = confirm(prompt);
              if (confirmed) {
                this.form.submit();
          Severity: Major
          Found in app/assets/javascripts/probation.js and 1 other location - About 3 hrs to fix
          app/assets/javascripts/probation.js on lines 12..20

          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 103.

          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

          Further Reading

          Method create has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

            def create
              @cohort = Cohort.find_by_id(params[:enrollment][:cohort_id])
              @course = Course.find_by_id(params[:enrollment][:course_id])
              @student = Student.find(params[:enrollment][:student_id])
              @previous_current_cohort = @student.cohort
          Severity: Minor
          Found in app/controllers/enrollments_controller.rb - About 2 hrs to fix

          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 index has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

            def index
              if params[:student_id]
                @student = Student.find_by_id(params[:student_id])
                if @student
                  @courses = @student.courses
          Severity: Minor
          Found in app/controllers/courses_controller.rb - About 2 hrs to fix

          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 after_sign_in_path_for has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def after_sign_in_path_for(user)
              if user.is_a? Admin
                user.otp_required_for_login ? course_path(user.current_course) : new_otp_path
              elsif user.is_a? Company
                company_path(user)
          Severity: Minor
          Found in app/controllers/application_controller.rb - About 1 hr to fix

          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 build_code_reviews has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def build_code_reviews
              code_review_params = Github.get_layout_params(layout_file_path)['code_reviews']
              if code_review_params.try(:any?)
                order_number = 0
                visible_day_of_week, visible_time, due_days_later, due_time, submissions_not_required, always_visible = code_review_params['settings'].values_at 'visible_day_of_week', 'visible_time', 'due_days_later', 'due_time', 'submissions_not_required', 'always_visible'
          Severity: Minor
          Found in app/models/course.rb - About 1 hr to fix

          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 destroy has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def destroy
              if params['really_destroy'] == 'true'
                enrollment = Enrollment.only_deleted.find(params[:id])
                enrollment.really_destroy!
                redirect_to student_courses_path(enrollment.student), notice: "Enrollment permanently removed: #{enrollment.course.description}"
          Severity: Minor
          Found in app/controllers/enrollments_controller.rb - About 1 hr to fix

          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 has a complexity of 8.
          Open

              $('#demographic_info_ssn').keyup(function(event) {

          Limit Cyclomatic Complexity (complexity)

          Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

          function a(x) {
              if (true) {
                  return x; // 1st path
              } else if (false) {
                  return x+1; // 2nd path
              } else {
                  return 4; // 3rd path
              }
          }

          Rule Details

          This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

          Examples of incorrect code for a maximum of 2:

          /*eslint complexity: ["error", 2]*/
          
          function a(x) {
              if (true) {
                  return x;
              } else if (false) {
                  return x+1;
              } else {
                  return 4; // 3rd path
              }
          }

          Examples of correct code for a maximum of 2:

          /*eslint complexity: ["error", 2]*/
          
          function a(x) {
              if (true) {
                  return x;
              } else {
                  return 4;
              }
          }

          Options

          Optionally, you may specify a max object property:

          "complexity": ["error", 2]

          is equivalent to

          "complexity": ["error", { "max": 2 }]

          Deprecated: the object property maximum is deprecated. Please use the property max instead.

          When Not To Use It

          If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

          Further Reading

          Related Rules

          • [max-depth](max-depth.md)
          • [max-len](max-len.md)
          • [max-nested-callbacks](max-nested-callbacks.md)
          • [max-params](max-params.md)
          • [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/

          Method update_student_as_admin has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update_student_as_admin
              @student = Student.find(params[:id])
              if @student.update(student_params)
                if student_params[:cohort_id]
                  redirect_to student_courses_path(@student), notice: "Current cohort for #{@student.name} has been set to #{@student.cohort.try(:description) || 'blank'}."
          Severity: Minor
          Found in app/controllers/students_controller.rb - About 1 hr to fix

            Method index has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

              def index
                if current_admin
                  @journals = CodeReview.where(journal: true)
                  if params[:cohort_id]
                    @cohort = Cohort.find(params[:cohort_id])
            Severity: Minor
            Found in app/controllers/journals_controller.rb - About 1 hr to fix

            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 get_status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def get_status
                if deleted?
                  "Archived"
                elsif courses_with_withdrawn.empty?
                  "Not enrolled"
            Severity: Minor
            Found in app/models/student.rb - About 1 hr to fix

            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
                if params[:source_course_id]
                  move_submissions
                elsif submission_params['times_submitted']
                  @submission = Submission.find(params[:id])
            Severity: Minor
            Found in app/controllers/submissions_controller.rb - About 1 hr to fix

            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 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def update
                if params[:source_course_id]
                  move_submissions
                elsif submission_params['times_submitted']
                  @submission = Submission.find(params[:id])
            Severity: Minor
            Found in app/controllers/submissions_controller.rb - About 1 hr to fix

              Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def create
                  @cohort = Cohort.find_by_id(params[:enrollment][:cohort_id])
                  @course = Course.find_by_id(params[:enrollment][:course_id])
                  @student = Student.find(params[:enrollment][:student_id])
                  @previous_current_cohort = @student.cohort
              Severity: Minor
              Found in app/controllers/enrollments_controller.rb - About 1 hr to fix

                Method set_class_days has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def set_class_days(number_of_weeks:, days_of_week:)
                    number_of_days = number_of_weeks * days_of_week.count
                    class_days = []
                    day = start_date
                    number_of_days.times do
                Severity: Minor
                Found in app/models/course.rb - About 1 hr to fix

                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

                Severity
                Category
                Status
                Source
                Language