jshoe/coursequestionbank

View on GitHub

Showing 64 of 64 total issues

Method update has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    problem = Problem.find(params[:id])

    if !params[:privacy].nil?
      authorize! :set_privacy, problem
Severity: Minor
Found in app/controllers/problems_controller.rb - About 6 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 has too many lines. [63/30]
Open

  def update
    problem = Problem.find(params[:id])

    if !params[:privacy].nil?
      authorize! :set_privacy, problem

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. [48/30]
Open

  def self.filter(user, filters, bump_problem)
    problems = Problem.search do
      any_of do
        with(:instructor_id, user.id)
        with(:is_public, true)
Severity: Minor
Found in app/models/problem.rb by rubocop

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. [48/30]
Open

  def create
    parent_uid = params[:parent_uid]
    if parent_uid
      previous_version = Problem.find_by_uid(params[:parent_uid])
      if !previous_version

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.

Cyclomatic complexity for update is too high. [22/6]
Open

  def update
    problem = Problem.find(params[:id])

    if !params[:privacy].nil?
      authorize! :set_privacy, problem

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.

Method update has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def update
    problem = Problem.find(params[:id])

    if !params[:privacy].nil?
      authorize! :set_privacy, problem
Severity: Major
Found in app/controllers/problems_controller.rb - About 2 hrs to fix

    Cyclomatic complexity for update_whitelist is too high. [13/6]
    Open

      def update_whitelist
        authorize! :manage, Whitelist
        username = params[:username] ? params[:username].strip : nil
        provider = params[:provider]
        privilege = params[:privilege]

    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.

    Cyclomatic complexity for create is too high. [11/6]
    Open

      def create
        parent_uid = params[:parent_uid]
        if parent_uid
          previous_version = Problem.find_by_uid(params[:parent_uid])
          if !previous_version

    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.

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

      def create
        parent_uid = params[:parent_uid]
        if parent_uid
          previous_version = Problem.find_by_uid(params[:parent_uid])
          if !previous_version
    Severity: Minor
    Found in app/controllers/problems_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

    Cyclomatic complexity for set_filters is too high. [9/6]
    Open

      def set_filters
        session[:filters] = session[:filters].merge params.slice(:search, :tags, :sort_by)
    
        if session[:filters][:tags].is_a? String
          session[:filters][:tags] = self.class.parse_list session[:filters][:tags]

    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.

    Cyclomatic complexity for filter is too high. [9/6]
    Open

      def self.filter(user, filters, bump_problem)
        problems = Problem.search do
          any_of do
            with(:instructor_id, user.id)
            with(:is_public, true)
    Severity: Minor
    Found in app/models/problem.rb by rubocop

    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.

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

      def create
        parent_uid = params[:parent_uid]
        if parent_uid
          previous_version = Problem.find_by_uid(params[:parent_uid])
          if !previous_version
    Severity: Minor
    Found in app/controllers/problems_controller.rb - About 1 hr to fix

      Method filter has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.filter(user, filters, bump_problem)
          problems = Problem.search do
            any_of do
              with(:instructor_id, user.id)
              with(:is_public, true)
      Severity: Minor
      Found in app/models/problem.rb - About 1 hr to fix

        Cyclomatic complexity for render_from_json is too high. [8/6]
        Open

          def self.render_from_json(json_code, uid, prev_uid)
            result = ""
            return "" if json_code == nil || json_code.length <= 2
            json_hash = JSON.parse(json_code)
            answers = json_hash["answers"]
        Severity: Minor
        Found in lib/ruql_renderer.rb by rubocop

        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.

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

          def set_filters
            session[:filters] = session[:filters].merge params.slice(:search, :tags, :sort_by)
        
            if session[:filters][:tags].is_a? String
              session[:filters][:tags] = self.class.parse_list session[:filters][:tags]
        Severity: Minor
        Found in app/controllers/problems_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 filter has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.filter(user, filters, bump_problem)
            problems = Problem.search do
              any_of do
                with(:instructor_id, user.id)
                with(:is_public, true)
        Severity: Minor
        Found in app/models/problem.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

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

              problem.find('.history_button').click(function() {
                problem.find('.supersede_form').hide();
                problem.find('.history_list').toggle();
                return false;
              });
        Severity: Major
        Found in app/assets/javascripts/problems.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/problems.js on lines 28..32

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

        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

              problem.find('.supersede_button').click(function() {
                problem.find('.supersede_form').toggle();
                problem.find('.history_list').hide();
                return false;
              });
        Severity: Major
        Found in app/assets/javascripts/problems.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/problems.js on lines 33..37

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

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

          def self.store_as_json(user, file)
            filename = file.path
            Quiz.nuke_from_orbit
            Quiz.instance_eval "#{IO.read(filename)}"
            collections = []
        Severity: Minor
        Found in app/models/ruql_reader.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 setup has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          setup: function() {
            $('.bloom-buttons').each(function() {
              var container = $(this);
              container.find('form').submit(function() {
                $.ajax({
        Severity: Minor
        Found in app/assets/javascripts/problems.js - About 1 hr to fix
          Severity
          Category
          Status
          Source
          Language