sleepepi/sleepportal

View on GitHub

Showing 436 of 436 total issues

Method user_has_action? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def user_has_action?(current_user, action)
    return true if current_user.all_sources.include?(self)
    result = false
    blocked = false
    self.rules.each do |rule|
Severity: Minor
Found in app/models/source.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

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

  def create
    @search = current_user.all_searches.find_by_id(params[:search_id])
    if @search and @report = @search.reports.create(user_id: current_user.id, name: params[:report][:name], is_dataset: params[:is_dataset])
      @element_id = (params[:is_dataset] == 'true') ? "dataset_tabs-#{@search.true_datasets.size + 1}" : "report_tabs-#{@search.true_reports.size + 1}"

Severity: Minor
Found in app/controllers/reports_controller.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

Avoid deeply nested control flow statements.
Open

            elsif statistic == 'avg'
              body_row[index] = (filtered_results.compact.size > 0) ? (filtered_results.compact.sum.to_f / filtered_results.compact.size).round(1) : 'n/a'
            elsif statistic == 'count'
              body_row[index] = filtered_results.size
            elsif statistic == '%'
Severity: Major
Found in app/models/report.rb - About 45 mins to fix

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

            if (isString(hash) && defined(val)) {
                key = hash;
                hash = {};
                hash[key] = val;
            }
    Severity: Minor
    Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 2077..2081

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

    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

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

                        if (regexRgba.test(stop[1])) {
                            colorObject = Color(stop[1]);
                            stopColor = colorObject.get('rgb');
                            stopOpacity = colorObject.get('a');
                        } else {
    Severity: Minor
    Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 5279..5286

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

    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 (isString(hash) && defined(val)) {
                key = hash;
                hash = {};
                hash[key] = val;
            }
    Severity: Minor
    Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 4718..4722

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

    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

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

                    if (regexRgba.test(stop[1])) {
                        colorObject = Color(stop[1]);
                        stopColor = colorObject.get('rgb');
                        stopOpacity = colorObject.get('a');
                    } else {
    Severity: Minor
    Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 4008..4015

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

    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

    Consider simplifying this complex logical expression.
    Open

                        } else if (key === 'translateX' || key === 'translateY' || key === 'rotation' ||
                                key === 'verticalAlign' || key === 'scaleX' || key === 'scaleY') {
                            doTransform = true;
                            skipAttr = true;
    
    
    Severity: Major
    Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

      Consider simplifying this complex logical expression.
      Open

              if (isDirtyAxisLength || isDirtyData || axis.isLinked || axis.forceRedraw ||
                  axis.userMin !== axis.oldUserMin || axis.userMax !== axis.oldUserMax) {
                  
                  // reset stacks
                  if (!axis.isXAxis) {
      Severity: Major
      Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if (maxTicks && maxTicks[key] && !axis.isDatetimeAxis && !axis.categories && !axis.isLinked && axis.options.alignTicks !== false) { // only apply to linear scale
                    var oldTickAmount = axis.tickAmount,
                        calculatedTickAmount = tickPositions.length,
                        tickAmount;
        
        
        Severity: Major
        Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                      if ((tick.isFirst && !tick.isLast && !pick(options.showFirstLabel, 1)) ||
                              (tick.isLast && !tick.isFirst && !pick(options.showLastLabel, 1))) {
                          show = false;
          
                      // Handle label overflow and show or hide accordingly
          Severity: Major
          Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    if (
                        (events && events.click) ||
                        (options.point && options.point.events && options.point.events.click) ||
                        options.allowPointSelect
                    ) {
            Severity: Major
            Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                      if (!this.isLinked && !this.isDatetimeAxis && tickPositions && tickPositions.length > (maxTicks[key] || 0) && this.options.alignTicks !== false) {
                          maxTicks[key] = tickPositions.length;
                      }
              Severity: Major
              Found in app/assets/javascripts/external/highcharts-3.0.7.src.js - About 40 mins to fix

                Consider simplifying this complex logical expression.
                Open

                            if (($(this).html() && !options.get('disableHiddenCheck') && $(this).is(':hidden')) || ($.fn.jquery < '1.3.0' && $(this).parents().is(':hidden')) || !$(this).parents('body').length) {
                                if (!options.get('composite') && $.data(this, '_jqs_pending')) {
                                    // remove any existing references to the element
                                    for (i = pending.length; i; i--) {
                                        if (pending[i - 1][0] == this) {
                Severity: Major
                Found in app/assets/javascripts/external/jquery.sparkline.js - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                            elsif val == '1 = 0' or (range.size == 1 and range[0].blank?) or (range.size == 2 and range[0].blank? and range[1].blank?)
                              all_conditions << '1 = 0'
                            elsif val == '1 = 1'
                              all_conditions << '1 = 1'
                            elsif criterium.variable.variable_type == 'date'
                  Severity: Major
                  Found in app/models/resolver.rb - About 40 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                                    if (hlSpotsEnabled || options.get('spotColor') ||
                                        (options.get('minSpotColor') || options.get('maxSpotColor') &&
                                            (yvalues[yvallast] === this.miny || yvalues[yvallast] === this.maxy))) {
                                        canvasWidth -= Math.ceil(spotRadius);
                                    }
                    Severity: Major
                    Found in app/assets/javascripts/external/jquery.sparkline.js - About 40 mins to fix

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

                                  axis.axisGroup = renderer.g('axis')
                                      .attr({ zIndex: options.zIndex || 2 })
                                      .add();
                      Severity: Minor
                      Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 2 other locations - About 40 mins to fix
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8037..8039
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8043..8045

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

                      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 3 locations. Consider refactoring.
                      Open

                                  axis.labelGroup = renderer.g('axis-labels')
                                      .attr({ zIndex: labelOptions.zIndex || 7 })
                                      .add();
                      Severity: Minor
                      Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 2 other locations - About 40 mins to fix
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8037..8039
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8040..8042

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

                      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 (match) {
                                      this.pixelWidth = match[1];
                                  } else {
                                      this.pixelWidth = $(canvas).width();
                                  }
                      Severity: Minor
                      Found in app/assets/javascripts/external/jquery.sparkline.js and 1 other location - About 40 mins to fix
                      app/assets/javascripts/external/jquery.sparkline.js on lines 2624..2628

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

                      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 3 locations. Consider refactoring.
                      Open

                                  axis.gridGroup = renderer.g('grid')
                                      .attr({ zIndex: options.gridZIndex || 1 })
                                      .add();
                      Severity: Minor
                      Found in app/assets/javascripts/external/highcharts-3.0.7.src.js and 2 other locations - About 40 mins to fix
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8040..8042
                      app/assets/javascripts/external/highcharts-3.0.7.src.js on lines 8043..8045

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

                      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