roqua/quby_engine

View on GitHub

Showing 107 of 107 total issues

Method value_by_values has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

        def value_by_values
          result = {}
          if value
            result = value.dup
            value.each_key do |key|
Severity: Minor
Found in lib/quby/answers/entities/answer.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 from_json has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def self.from_json(json)
        # TODO: last_update
        Entities::Questionnaire.new(json.fetch("key"), json).tap do |questionnaire|
          questionnaire.title = json.fetch("title")
          questionnaire.description = json.fetch("description")
Severity: Major
Found in lib/quby/questionnaires/deserializer.rb - About 2 hrs to fix

    Method build_question_validation has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def self.build_question_validation(attrs)
            base_validation = {
              type: attrs.fetch("type").to_sym,
              explanation: attrs["explanation"] # not always specified for min/max validation
            }
    Severity: Major
    Found in lib/quby/questionnaires/deserializer.rb - About 2 hrs to fix

      Function handleUpHotKeys has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function handleUpHotKeys(event){
          event.which = event.which || event.keyCode;
          if ($(lastInput).is("input[type=submit]") && (event.which == 32 || event.which == 13)){
              event.target.click();
              return;
      Severity: Major
      Found in app/assets/javascripts/quby/answers/hotkeys.js - About 2 hrs to fix

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

                          if ($(inputs[0]).attr('class') === 'date') {
                            try {
                              if(allDateFieldsFilledIn(inputs)) {
                                var enteredDate = parsePartialDate(inputs);
                                var maximumDate = new Date(validation.value)
        Severity: Major
        Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 2 hrs to fix
        app/assets/javascripts/quby/answers/validation.js on lines 65..83

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

        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

                          if ($(inputs[0]).attr('class') === 'date') {
                            try {
                              if(allDateFieldsFilledIn(inputs)) {
                                var enteredDate = parsePartialDate(inputs);
                                var minimumDate = new Date(validation.value);
        Severity: Major
        Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 2 hrs to fix
        app/assets/javascripts/quby/answers/validation.js on lines 86..104

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

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

        function assignValue(qkey, val){
            var inputs;
            if(val instanceof Object){//checkbox vals are passed as an object hash
                inputs = $("[name^='answer["+qkey+"_'][type!='hidden']");
            } else {
        Severity: Minor
        Found in app/assets/javascripts/quby/answers/rest.js - 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 validate has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def validate
                  questionnaire.questions.each do |question|
                    next unless question
                    next if question.hidden?
        
        
        Severity: Major
        Found in lib/quby/answers/services/answer_validator.rb - About 2 hrs to fix

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

                def self.build_chart(questionnaire, chart_json)
                  base_args = {
                    title: chart_json.fetch("title"),
                    plottables: chart_json.fetch("plottables").map do |plottable_json|
                      Quby::Questionnaires::Entities::Charting::Plottable.new(
          Severity: Minor
          Found in lib/quby/questionnaires/deserializer.rb - About 1 hr to fix

            Method calculate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                    def calculate # rubocop:disable Metrics/MethodLength
                      results = {}
                      score_results = {}
                      action_results = {}
                      completion_result = {}
            Severity: Minor
            Found in lib/quby/answers/services/outcome_calculation.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 initialize has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def initialize(key, options = {})
                      super(options)
            
                      @extra_data ||= {}
                      @options = []
            Severity: Minor
            Found in lib/quby/questionnaires/entities/question.rb - About 1 hr to fix

              Function handleDownHotKeys has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function handleDownHotKeys(event){
                  event.which = event.charCode || event.which || event.keyCode;
                  if ($(lastInput).is("textarea") || $(lastInput).is("input[type=submit]") && (event.which == 32 || event.which == 13)) {
                    return;
                  }
              Severity: Minor
              Found in app/assets/javascripts/quby/answers/hotkeys.js - About 1 hr to fix

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

                function setAllCheckboxes(checked, allKey, nothingKey, question, checkValue){
                    if(checked){
                        // Setting all other checkboxes to checkValue
                        check_boxes = $("#answer_"+question+"_input").find("input[type=checkbox]:not(:disabled)");
                        if(check_boxes.length == 0){
                Severity: Minor
                Found in app/assets/javascripts/quby/answers/rest.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 update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    def update
                      if session[:has_downloaded_pdf_for] == @answer.id && defined?(Appsignal) && on_ios_safari?
                        Appsignal.increment_counter("ios_safari_downloaded_pdf_and_pressed_done", 1)
                      end
                
                
                Severity: Minor
                Found in app/controllers/quby/answers_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 to_codebook has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                        def to_codebook(questionnaire, opts)
                          return nil if inner_title
                          output = []
                
                          if question.type == :check_box
                Severity: Minor
                Found in lib/quby/questionnaires/entities/question_option.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 cleanup_input has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                        def cleanup_input
                          questionnaire.questions.each do |question|
                            next unless question
                            next if question.hidden?
                
                
                Severity: Minor
                Found in lib/quby/answers/services/answer_validations.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

                                    try {
                                      if(allDateFieldsFilledIn(inputs)) {
                                        var enteredDate = parsePartialDate(inputs);
                                        var maximumDate = new Date(validation.value)
                                        if(enteredDate > maximumDate) {
                Severity: Major
                Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 1 hr to fix
                app/assets/javascripts/quby/answers/validation.js on lines 66..74

                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

                Function handleAjaxFormRequests has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function handleAjaxFormRequests(prepareDisplayModeCallback) {
                  $(document).on('ajax:success', "form", function(event, data, status, xhr) {
                    content_type = (xhr.getResponseHeader("content-type")||"").split(';')[0];
                    if (content_type == 'text/html') { // not json response
                      $('#content').replaceWith(data);
                Severity: Minor
                Found in app/assets/javascripts/quby/answers/rest.js - About 1 hr to fix

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

                                case "answer_group_maximum":
                                    var count = calculateAnswerGroup(validation.group, panel);
                                    if(count.visible > 0 && count.answered > validation.value){
                                        pushFailVal(validation.type);
                                    }
                  Severity: Major
                  Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/quby/answers/validation.js on lines 161..166

                  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

                                case "answer_group_minimum":
                                    var count = calculateAnswerGroup(validation.group, panel);
                                    if(count.visible > 0 && count.answered < validation.value){
                                        pushFailVal(validation.type);
                                    }
                  Severity: Major
                  Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/quby/answers/validation.js on lines 167..172

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language