wikimedia/mediawiki-extensions-VisualEditor

View on GitHub
modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js

Summary

Maintainability
D
2 days
Test Coverage

Function onReplacePart has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
    const removePages = [];

    if ( removed ) {
        // Remove parameter pages of removed templates
Severity: Minor
Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 5 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

File ve.ui.MWTemplateDialog.js has 306 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * VisualEditor user interface MWTemplateDialog class.
 *
 * @copyright See AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
Severity: Minor
Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 3 hrs to fix

    Function getSetupProcess has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
        data = data || {};
        return ve.ui.MWTemplateDialog.super.prototype.getSetupProcess.call( this, data )
            .next( () => {
                let promise;
    Severity: Major
    Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 2 hrs to fix

      Function onReplacePart has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
          const removePages = [];
      
          if ( removed ) {
              // Remove parameter pages of removed templates
      Severity: Minor
      Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 1 hr to fix

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

        ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
            if ( action === 'done' ) {
                return new OO.ui.Process( () => {
                    const deferred = ve.createDeferred();
                    this.checkRequiredParameters().done( () => {
        Severity: Minor
        Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 1 hr to fix

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

          ve.ui.MWTemplateDialog.prototype.checkRequiredParameters = function () {
              const blankRequired = [],
                  deferred = ve.createDeferred();
          
              this.bookletLayout.stackLayout.getItems().forEach( ( page ) => {
          Severity: Minor
          Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                                if ( reselect ) {
                                    this.bookletLayout.focusPart( reselect );
                                }
            Severity: Major
            Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 45 mins to fix

              Function updateTitle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              ve.ui.MWTemplateDialog.prototype.updateTitle = function () {
                  let title = ve.msg( 'visualeditor-dialog-transclusion-loading' );
              
                  if ( this.transclusionModel.isSingleTemplate() ) {
                      const part = this.transclusionModel.getParts()[ 0 ];
              Severity: Minor
              Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js - About 35 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

                          this.bookletLayout.getPagesOrdered().forEach( ( page ) => {
                              if ( page instanceof ve.ui.MWParameterPage ) {
                                  page.updateSize();
                              }
                          } );
              Severity: Major
              Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js and 1 other location - About 1 hr to fix
              modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js on lines 599..603

              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 ( part instanceof ve.dm.MWTemplateModel ) {
                      return new ve.ui.MWTemplatePage( part, part.getId(), { $overlay: this.$overlay, isReadOnly: this.isReadOnly() } );
                  } else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
                      return new ve.ui.MWTemplatePlaceholderPage(
                          part,
              Severity: Minor
              Found in modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js and 1 other location - About 45 mins to fix
              modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js on lines 275..277

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

              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