MiniProfiler/rack-mini-profiler

View on GitHub
lib/html/includes.js

Summary

Maintainability
F
3 wks
Test Coverage

Function _MiniProfiler has a Cognitive Complexity of 437 (exceeds 5 allowed). Consider refactoring.
Open

var _MiniProfiler = (function() {
  var _arguments = arguments;
  var options,
    container,
    controls,
Severity: Minor
Found in lib/html/includes.js - About 1 wk 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 _MiniProfiler has 1291 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var _MiniProfiler = (function() {
  var _arguments = arguments;
  var options,
    container,
    controls,
Severity: Major
Found in lib/html/includes.js - About 6 days to fix

    File includes.js has 1299 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    "use strict";
    
    var _MiniProfiler = (function() {
      var _arguments = arguments;
      var options,
    Severity: Major
    Found in lib/html/includes.js - About 3 days to fix

      Function initPopupView has 189 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        var initPopupView = function initPopupView() {
          if (options.authorized) {
            // all fetched profilings will go in here
            container = document.createElement("div");
            container.className = "profiler-results";
      Severity: Major
      Found in lib/html/includes.js - About 7 hrs to fix

        Function getSqlTimings has 130 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            getSqlTimings: function getSqlTimings(root) {
              var result = [],
                addToResults = function addToResults(timing) {
                  if (timing.sql_timings) {
                    for (var i = 0, sqlTiming; i < timing.sql_timings.length; i++) {
        Severity: Major
        Found in lib/html/includes.js - About 5 hrs to fix

          Function init has 129 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              init: function init() {
                var script = document.getElementById("mini-profiler");
                if (!script || !script.getAttribute) return;
          
                this.options = options = (function() {
          Severity: Major
          Found in lib/html/includes.js - About 5 hrs to fix

            Function toggleShortcutEvent has 73 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              var toggleShortcutEvent = function toggleShortcutEvent(e) {
                // simplified version of https://github.com/jeresig/jquery.hotkeys/blob/master/jquery.hotkeys.js
                var shortcut = options.toggleShortcut.toLowerCase();
                var modifier = "";
                ["alt", "ctrl", "shift"].forEach(function(k) {
            Severity: Major
            Found in lib/html/includes.js - About 2 hrs to fix

              Function buttonShow has 72 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                var buttonShow = function buttonShow(json) {
                  var result = renderTemplate(json);
                  totalTime += parseFloat(json.duration_milliseconds, 10);
                  totalSqlCount += parseInt(json.sql_count);
                  reqs++;
              Severity: Major
              Found in lib/html/includes.js - About 2 hrs to fix

                Function fetchResults has 70 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  var fetchResults = function fetchResults(ids) {
                    var clientPerformance, clientProbes, i, j, p, id, idx;
                
                    for (i = 0; i < ids.length; i++) {
                      id = ids[i];
                Severity: Major
                Found in lib/html/includes.js - About 2 hrs to fix

                  Function toggleHidden has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    var toggleHidden = function toggleHidden(popup) {
                      var trivial = popup.querySelector(".profiler-toggle-trivial");
                      var childrenTime = popup.querySelector(
                        ".profiler-toggle-duration-with-children"
                      );
                  Severity: Minor
                  Found in lib/html/includes.js - About 1 hr to fix

                    Function fetch has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            window.fetch = function(input, init) {
                              var originalFetchRun = __originalFetch(input, init);
                    
                              originalFetchRun.then(function(response) {
                                try {
                    Severity: Minor
                    Found in lib/html/includes.js - About 1 hr to fix

                      Function onClickEvents has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        var onClickEvents = function onClickEvents(e) {
                          // this happens on every keystroke, and :visible is crazy expensive in IE <9
                          // and in this case, the display:none check is sufficient.
                          var popup = toArray(document.querySelectorAll(".profiler-popup")).filter(
                            function(el) {
                      Severity: Minor
                      Found in lib/html/includes.js - About 1 hr to fix

                        Function initControls has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          var initControls = function initControls(container) {
                            if (options.showControls) {
                              var _controls = document.createElement("div");
                        
                              _controls.classList.add("profiler-controls");
                        Severity: Minor
                        Found in lib/html/includes.js - About 1 hr to fix

                          Function toQueryString has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            var toQueryString = function toQueryString(data, parentKey) {
                              var result = [];
                              for (var key in data) {
                                var val = data[key];
                                var newKey = !parentKey ? key : parentKey + "[" + key + "]";
                          Severity: Minor
                          Found in lib/html/includes.js - About 1 hr to fix

                            Function getClientTimings has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                getClientTimings: function getClientTimings(clientTimings) {
                                  var list = [];
                                  var t;
                                  if (!clientTimings.timings) return [];
                            
                            
                            Severity: Minor
                            Found in lib/html/includes.js - About 1 hr to fix

                              Function send has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                    XMLHttpRequest.prototype.send = function(data) {
                                      ajaxStartTime = new Date();
                                      this.addEventListener("load", function() {
                                        // responseURL isn't available in IE11
                                        if (
                              Severity: Minor
                              Found in lib/html/includes.js - About 1 hr to fix

                                Consider simplifying this complex logical expression.
                                Open

                                    } else if (popup.style.display === "block") {
                                      hidePopup =
                                        isEscPress ||
                                        (e.type == "click" &&
                                          !(popup !== e.target && popup.contains(e.target)) &&
                                Severity: Major
                                Found in lib/html/includes.js - About 1 hr to fix

                                  Consider simplifying this complex logical expression.
                                  Open

                                      if (bg && bg.style.display === "block") {
                                        hideQueries =
                                          isEscPress ||
                                          (e.type == "click" &&
                                            !(queries !== e.target && queries.contains(e.target)) &&
                                  Severity: Major
                                  Found in lib/html/includes.js - About 1 hr to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                  if (stringIds) {
                                                    var ids = stringIds.split(",");
                                                    fetchResults(ids);
                                                  }
                                    Severity: Major
                                    Found in lib/html/includes.js - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                      if (this.readyState == 4) {
                                                        var stringIds = this.getResponseHeader("X-MiniProfiler-Ids");
                                      
                                                        if (stringIds) {
                                                          var ids = stringIds.split(",");
                                      Severity: Major
                                      Found in lib/html/includes.js - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                        if (this.miniprofiler.prev_onreadystatechange !== null)
                                                          return this.miniprofiler.prev_onreadystatechange.apply(
                                                            this,
                                                            arguments
                                                          );
                                        Severity: Major
                                        Found in lib/html/includes.js - About 45 mins to fix

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

                                                    if (duration.finish < item.finish) {
                                                      if (duration.finish < item.start) {
                                                        newList.push(item);
                                                        continue;
                                                      }
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 2 hrs to fix
                                          lib/html/includes.js on lines 1322..1332

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

                                          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 (duration.start > item.start) {
                                                      if (duration.start > item.finish) {
                                                        newList.push(item);
                                                        continue;
                                                      }
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 2 hrs to fix
                                          lib/html/includes.js on lines 1334..1344

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

                                          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

                                                  (e.type == "click" &&
                                                    !(queries !== e.target && queries.contains(e.target)) &&
                                                    !(popup !== e.target && popup.contains(e.target)));
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 544..546

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

                                          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

                                                  (e.type == "click" &&
                                                    !(popup !== e.target && popup.contains(e.target)) &&
                                                    !(button !== e.target && button.contains(e.target)) &&
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 538..540

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

                                          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

                                                container.addEventListener("mouseleave", function() {
                                                  if (this.classList.contains("profiler-min")) {
                                                    this.querySelector(".profiler-min-max").style.display = "none";
                                                  }
                                                });
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 752..756

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

                                          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

                                                container.addEventListener("mouseenter", function() {
                                                  if (this.classList.contains("profiler-min")) {
                                                    this.querySelector(".profiler-min-max").style.display = "block";
                                                  }
                                                });
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 757..761

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

                                          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 (timing.children) {
                                                      for (var i = 0; i < timing.children.length; i++) {
                                                        countSql(timing.children[i]);
                                                      }
                                                    }
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 1307..1311

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

                                          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 (timing.children) {
                                                      for (var i = 0; i < timing.children.length; i++) {
                                                        addToResults(timing.children[i]);
                                                      }
                                                    }
                                          Severity: Major
                                          Found in lib/html/includes.js and 1 other location - About 1 hr to fix
                                          lib/html/includes.js on lines 1453..1457

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

                                          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

                                                  me.nextGap = {
                                                    duration: (root.duration_milliseconds - time).toFixed(2),
                                                    start: time,
                                                    finish: root.duration_milliseconds
                                                  };
                                          Severity: Minor
                                          Found in lib/html/includes.js and 1 other location - About 35 mins to fix
                                          lib/html/includes.js on lines 1424..1428

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

                                          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

                                                  r.prevGap = {
                                                    duration: (r.start_milliseconds - time).toFixed(2),
                                                    start: time,
                                                    finish: r.start_milliseconds
                                                  };
                                          Severity: Minor
                                          Found in lib/html/includes.js and 1 other location - About 35 mins to fix
                                          lib/html/includes.js on lines 1436..1440

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

                                          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

                                          There are no issues that match your filters.

                                          Category
                                          Status