phpmyadmin/phpmyadmin

View on GitHub
resources/js/src/modules/ajax.ts

Summary

Maintainability
F
1 wk
Test Coverage

File ajax.ts has 627 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import $ from 'jquery';
import { Navigation } from './navigation.ts';
import { CommonParams } from './common.ts';
import highlightSql from './sql-highlight.ts';
import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.ts';
Severity: Major
Found in resources/js/src/modules/ajax.ts - About 1 day to fix

    Function requestHandler has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        requestHandler: function (event) {
            // In some cases we don't want to handle the request here and either
            // leave the browser deal with it natively (e.g: file download)
            // or leave an existing ajax event handler present elsewhere deal with it
            var href = $(this).attr('href');
    Severity: Minor
    Found in resources/js/src/modules/ajax.ts - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function responseHandler has 139 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        responseHandler: function (data): void {
            if (typeof data === 'undefined' || data === null) {
                return;
            }
    
    
    Severity: Major
    Found in resources/js/src/modules/ajax.ts - About 5 hrs to fix

      Function requestHandler has 85 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          requestHandler: function (event) {
              // In some cases we don't want to handle the request here and either
              // leave the browser deal with it natively (e.g: file download)
              // or leave an existing ajax event handler present elsewhere deal with it
              var href = $(this).attr('href');
      Severity: Major
      Found in resources/js/src/modules/ajax.ts - About 3 hrs to fix

        Function loginResponseHandler has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            loginResponseHandler: function (data): void {
                if (typeof data === 'undefined' || data === null) {
                    return;
                }
        
        
        Severity: Minor
        Found in resources/js/src/modules/ajax.ts - 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 loginResponseHandler has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            loginResponseHandler: function (data): void {
                if (typeof data === 'undefined' || data === null) {
                    return;
                }
        
        
        Severity: Major
        Found in resources/js/src/modules/ajax.ts - About 3 hrs to fix

          Function getFatalErrorHandler has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              getFatalErrorHandler: function () {
                  return function (event, request, settings) {
                      if (AJAX.debug) {
                          // eslint-disable-next-line no-console
                          console.log('AJAX error: status=' + request.status + ', text=' + request.statusText);
          Severity: Minor
          Found in resources/js/src/modules/ajax.ts - 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

          Function lockPageHandler has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              lockPageHandler: function (event): void {
                  // don't consider checkbox event
                  if (typeof event.target !== 'undefined') {
                      if (event.target.type === 'checkbox') {
                          return;
          Severity: Minor
          Found in resources/js/src/modules/ajax.ts - 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

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

              getFatalErrorHandler: function () {
                  return function (event, request, settings) {
                      if (AJAX.debug) {
                          // eslint-disable-next-line no-console
                          console.log('AJAX error: status=' + request.status + ', text=' + request.statusText);
          Severity: Minor
          Found in resources/js/src/modules/ajax.ts - About 1 hr to fix

            Function lockPageHandler has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                lockPageHandler: function (event): void {
                    // don't consider checkbox event
                    if (typeof event.target !== 'undefined') {
                        if (event.target.type === 'checkbox') {
                            return;
            Severity: Minor
            Found in resources/js/src/modules/ajax.ts - About 1 hr to fix

              Function removeSubmitEvents has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  removeSubmitEvents: function () {
                      // Registering the onload event for functions.js
                      // ensures that it will be fired for all pages
                      $('form').not('.ajax').not('.disableAjax').each(function () {
                          if ($(this).attr('onsubmit')) {
              Severity: Minor
              Found in resources/js/src/modules/ajax.ts - About 1 hr to fix

                Function responseHandler has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    responseHandler: function (data): void {
                        if (typeof data === 'undefined' || data === null) {
                            return;
                        }
                
                
                Severity: Minor
                Found in resources/js/src/modules/ajax.ts - 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 loadEventHandler has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    loadEventHandler: function () {
                        return function () {
                            var menuContent = $('<div></div>')
                                .append($('#server-breadcrumb').clone())
                                .append($('#topmenucontainer').clone())
                Severity: Minor
                Found in resources/js/src/modules/ajax.ts - About 1 hr to fix

                  Function load has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          load: function (files, callback = undefined): void {
                              var self = this;
                              var i;
                              // Clear loaded scripts if they are from another version of phpMyAdmin.
                              // Depends on common params being set before loading scripts in responseHandler
                  Severity: Minor
                  Found in resources/js/src/modules/ajax.ts - About 1 hr to fix

                    Function load has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            load: function (files, callback = undefined): void {
                                var self = this;
                                var i;
                                // Clear loaded scripts if they are from another version of phpMyAdmin.
                                // Depends on common params being set before loading scripts in responseHandler
                    Severity: Minor
                    Found in resources/js/src/modules/ajax.ts - 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

                    Avoid too many return statements within this function.
                    Open

                                return false;
                    Severity: Major
                    Found in resources/js/src/modules/ajax.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                          return false;
                      Severity: Major
                      Found in resources/js/src/modules/ajax.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return true;
                        Severity: Major
                        Found in resources/js/src/modules/ajax.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return false;
                          Severity: Major
                          Found in resources/js/src/modules/ajax.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return true;
                            Severity: Major
                            Found in resources/js/src/modules/ajax.ts - About 30 mins to fix

                              Function done has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                      done: function (script, callback): void {
                                          if ($.inArray(script, this.scriptsToBeFired)) {
                                              AJAX.fireOnload(script);
                                          }
                              
                              
                              Severity: Minor
                              Found in resources/js/src/modules/ajax.ts - About 25 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

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

                                              if (data.errors) {
                                                  $('<div></div>', { id: 'pma_errors', class: 'clearfloat d-print-none' })
                                                      .insertAfter('#selflink')
                                                      .append(data.errors);
                              
                              
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 1 day to fix
                              resources/js/src/modules/ajax.ts on lines 395..425

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

                              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 (data.errors) {
                                          $('<div></div>', { id: 'pma_errors', class: 'clearfloat d-print-none' })
                                              .insertAfter('#selflink')
                                              .append(data.errors);
                              
                              
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 1 day to fix
                              resources/js/src/modules/ajax.ts on lines 600..630

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

                              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

                                  registerOnload: function (file, func) {
                                      var eventName = 'onload_' + AJAX.hash(file);
                                      $(document).on(eventName, func);
                                      if (this.debug) {
                                          // eslint-disable-next-line no-console
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 2 hrs to fix
                              resources/js/src/modules/ajax.ts on lines 109..121

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

                              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

                                  registerTeardown: function (file, func) {
                                      var eventName = 'teardown_' + AJAX.hash(file);
                                      $(document).on(eventName, func);
                                      if (this.debug) {
                                          // eslint-disable-next-line no-console
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 2 hrs to fix
                              resources/js/src/modules/ajax.ts on lines 86..98

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

                              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

                                  fireTeardown: function (file): void {
                                      var eventName = 'teardown_' + AJAX.hash(file);
                                      $(document).triggerHandler(eventName);
                                      if (this.debug) {
                                          // eslint-disable-next-line no-console
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 2 hrs to fix
                              resources/js/src/modules/ajax.ts on lines 128..138

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

                              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

                                  fireOnload: function (file): void {
                                      var eventName = 'onload_' + AJAX.hash(file);
                                      $(document).trigger(eventName);
                                      if (this.debug) {
                                          // eslint-disable-next-line no-console
                              Severity: Major
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 2 hrs to fix
                              resources/js/src/modules/ajax.ts on lines 145..155

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

                              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 (data.fieldWithError) {
                                              $(':input.error').removeClass('error');
                                              $('#' + data.fieldWithError).addClass('error');
                                          }
                              Severity: Minor
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 40 mins to fix
                              resources/js/src/modules/ajax.ts on lines 470..473

                              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 (data.fieldWithError) {
                                              $(':input.error').removeClass('error');
                                              $('#' + data.fieldWithError).addClass('error');
                                          }
                              Severity: Minor
                              Found in resources/js/src/modules/ajax.ts and 1 other location - About 40 mins to fix
                              resources/js/src/modules/ajax.ts on lines 660..663

                              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

                              There are no issues that match your filters.

                              Category
                              Status