Showing 41 of 41 total issues

File hitme.js has 479 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// returns a unique ID to be used to identify an element within the
// webpage. Depends on the current state of the page, i.e. if we already
// are in ask-skipped-questions-again mode.
function getUniqId(q, a) {
  var qid = (typeof q === 'object' ? q.id : q);
Severity: Minor
Found in app/assets/javascripts/hitme.js - About 7 hrs to fix

    Function StatReporting has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    function StatReporting() {
      var start_time = null;
      var end_time = null;
      var question_id = null;
      var selected_answers = null;
    Severity: Minor
    Found in app/assets/javascripts/stat_reporting.js - About 3 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

    Function _showNextQuestion has 79 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _showNextQuestion: function() {
        this.questPositionPointer++;
        var q = window.currentQuestion = this.questions[this.questPositionPointer];
        var code = '<div style="display:none" id="'+getUniqId(q.id)+'" class="box hideMeOnMore">'; // outer box
    
    
    Severity: Major
    Found in app/assets/javascripts/hitme.js - About 3 hrs to fix

      Function StatReporting has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function StatReporting() {
        var start_time = null;
        var end_time = null;
        var question_id = null;
        var selected_answers = null;
      Severity: Major
      Found in app/assets/javascripts/stat_reporting.js - About 3 hrs to fix

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

        function getMultipleQuestion(questionIds, context, successCallback) {
          $.ajax({
            url: Routes.main_multiple_question_path({id: questionIds}),
          }).done(function(data) {
            successCallback(context, data);
        Severity: Major
        Found in app/assets/javascripts/hitme.js and 1 other location - About 2 hrs to fix
        app/assets/javascripts/hitme.js on lines 207..215

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

        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

        function getSingleQuestion(questionId, context, successCallback) {
          $.ajax({
            url: Routes.main_single_question_path({id: questionId}),
          }).done(function(data) {
            successCallback(context, data);
        Severity: Major
        Found in app/assets/javascripts/hitme.js and 1 other location - About 2 hrs to fix
        app/assets/javascripts/hitme.js on lines 217..225

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

        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

        Function XkcdLoader has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        var XkcdLoader = (function() {
          var insertImmediately = false;
          var preloaded = false;
          var comic = null;
        
        
        Severity: Minor
        Found in app/assets/javascripts/xkcd.js - About 1 hr to fix

          Function _handleQuestionSubmit has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _handleQuestionSubmit: function() {
              // gather details
              //~ var question = getQuestionById($(this).data('qid'));
              var quest = window.currentQuestion;
              var answerChooser = $(this).parent().siblings(".answer-chooser, .answer-chooser-matrix").first();
          Severity: Minor
          Found in app/assets/javascripts/hitme.js - About 1 hr to fix

            Function _showNextQuestion has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              _showNextQuestion: function() {
                this.questPositionPointer++;
                var q = window.currentQuestion = this.questions[this.questPositionPointer];
                var code = '<div style="display:none" id="'+getUniqId(q.id)+'" class="box hideMeOnMore">'; // outer box
            
            
            Severity: Minor
            Found in app/assets/javascripts/hitme.js - 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 overwrite_reviews has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              def overwrite_reviews
                @question = Question.includes(:reviews).find(params[:question_id])
                time = Time.now.strftime("%Y-%m-%d %H:%M")
                okay = true
                @question.reviews.each do |r|
            Severity: Minor
            Found in app/controllers/questions_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 duplicate_question_and_answers has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.duplicate_question_and_answers
                require 'set'
            
                same = [], diff = []
                sql = 'select min(q.id), q2.id from questions as q
            Severity: Minor
            Found in app/models/question.rb - About 1 hr to fix

              Method duplicate_question_and_answers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.duplicate_question_and_answers
                  require 'set'
              
                  same = [], diff = []
                  sql = 'select min(q.id), q2.id from questions as q
              Severity: Minor
              Found in app/models/question.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 XkcdLoader has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              var XkcdLoader = (function() {
                var insertImmediately = false;
                var preloaded = false;
                var comic = null;
              
              
              Severity: Minor
              Found in app/assets/javascripts/xkcd.js - 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 select_random_roulette has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def select_random_roulette(question_ids, n, user)
                  logger.debug "### roulette selection"
                  probs = wrong_ratio_for(question_ids, user)
              
                  selected = []
              Severity: Minor
              Found in app/helpers/random_selection_helper.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 new has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def new
                  @question = Question.new
              
                  if params['parent']
                    s = params['parent'].split('_', 2)
              Severity: Minor
              Found in app/controllers/questions_controller.rb - About 55 mins 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 select_random has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def select_random(question_ids, cnt)
                  big_sample = if signed_in?
                    # select questions depending on how often they were answered
                    # correctly.
                    select_random_roulette(question_ids, cnt, current_user)
              Severity: Minor
              Found in app/helpers/random_selection_helper.rb - About 55 mins 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 redirect_to has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def redirect_to(options = {}, response_status = {})
                  return super(options, response_status) unless Rails.env.production?
              
                  case options
                  when String
              Severity: Minor
              Found in app/helpers/application_helper.rb - About 55 mins 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 _handleQuestionSubmit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                _handleQuestionSubmit: function() {
                  // gather details
                  //~ var question = getQuestionById($(this).data('qid'));
                  var quest = window.currentQuestion;
                  var answerChooser = $(this).parent().siblings(".answer-chooser, .answer-chooser-matrix").first();
              Severity: Minor
              Found in app/assets/javascripts/hitme.js - About 55 mins 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 suspicious_associations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def suspicious_associations
                  # fcategories and all associated answers (ignoring subquests)
                  root_cats = Category.includes(:questions => [:answers])
                  root_cats_answers = {}
                  root_cats.each do |rc|
              Severity: Minor
              Found in app/controllers/categories_controller.rb - About 55 mins 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_question_stat_counts has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_question_stat_counts(questions = nil)
                  filter = {}
              
                  if questions
                    questions = [questions] unless questions.is_a?(Array)
              Severity: Minor
              Found in app/helpers/questions_helper.rb - About 45 mins 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