wikimedia/mediawiki-extensions-VisualEditor

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

Summary

Maintainability
F
1 wk
Test Coverage

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

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

    Function initialize has 228 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    ve.ui.MWGalleryDialog.prototype.initialize = function () {
        // Parent method
        ve.ui.MWGalleryDialog.super.prototype.initialize.call( this );
    
        // States
    Severity: Major
    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 day to fix

      Function insertOrUpdateNode has 115 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      ve.ui.MWGalleryDialog.prototype.insertOrUpdateNode = function () {
          const surfaceModel = this.getFragment().getSurface(),
              surfaceModelDocument = surfaceModel.getDocument(),
              items = this.galleryGroup.items,
              data = [];
      Severity: Major
      Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 4 hrs to fix

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

        ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
            return ve.ui.MWGalleryDialog.super.prototype.getSetupProcess.call( this, data )
                .next( () => {
                    const namespaceIds = mw.config.get( 'wgNamespaceIds' ),
                        mwData = this.selectedNode && this.selectedNode.getAttribute( 'mw' ),
        Severity: Major
        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 4 hrs to fix

          Function getSetupProcess has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
          Open

          ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
              return ve.ui.MWGalleryDialog.super.prototype.getSetupProcess.call( this, data )
                  .next( () => {
                      const namespaceIds = mw.config.get( 'wgNamespaceIds' ),
                          mwData = this.selectedNode && this.selectedNode.getAttribute( 'mw' ),
          Severity: Minor
          Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - 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 onRequestImagesSuccess has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) {
              const thumbUrls = {},
                  items = [],
                  config = { isMobile: this.isMobile, draggable: !this.isReadOnly() };
          
          
          Severity: Minor
          Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

            Function isSaveable has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            ve.ui.MWGalleryDialog.prototype.isSaveable = function () {
                // Check attributes
                if ( this.originalMwDataNormalized ) {
                    const mwDataCopy = ve.copy( this.selectedNode.getAttribute( 'mw' ) );
                    this.updateMwData( mwDataCopy );
            Severity: Minor
            Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

            Cognitive Complexity

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

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

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

            Further reading

            Function insertOrUpdateNode has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            ve.ui.MWGalleryDialog.prototype.insertOrUpdateNode = function () {
                const surfaceModel = this.getFragment().getSurface(),
                    surfaceModelDocument = surfaceModel.getDocument(),
                    items = this.galleryGroup.items,
                    data = [];
            Severity: Minor
            Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

            Cognitive Complexity

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

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

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

            Further reading

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

            ve.ui.MWGalleryDialog.prototype.onHighlightItem = function ( item ) {
                // Unhighlight previous item
                if ( this.highlightedItem ) {
                    this.highlightedItem.toggleHighlighted( false );
                }
            Severity: Minor
            Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

              Function getTeardownProcess has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              ve.ui.MWGalleryDialog.prototype.getTeardownProcess = function ( data ) {
                  return ve.ui.MWGalleryDialog.super.prototype.getTeardownProcess.call( this, data )
                      .first( () => {
                          // Layouts
                          this.indexLayout.setTabPanel( 'images' );
              Severity: Minor
              Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

                Function getImportRules has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                ve.ui.MWGalleryDialog.static.getImportRules = function () {
                    const rules = ve.copy( ve.init.target.constructor.static.importRules );
                    return ve.extendObject(
                        rules,
                        {
                Severity: Minor
                Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

                  Function getImageLinearData has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      function getImageLinearData( galleryItem ) {
                          const size = scaleImage(
                              parseInt( galleryItem.height ),
                              parseInt( galleryItem.width ),
                              parseInt( mwData.attrs.heights || this.defaults.imageHeight ),
                  Severity: Minor
                  Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 1 hr to fix

                    Function onRequestImagesSuccess has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                    ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) {
                        const thumbUrls = {},
                            items = [],
                            config = { isMobile: this.isMobile, draggable: !this.isReadOnly() };
                    
                    
                    Severity: Minor
                    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - 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

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

                    ve.ui.MWGalleryDialog.prototype.initialize = function () {
                        // Parent method
                        ve.ui.MWGalleryDialog.super.prototype.initialize.call( this );
                    
                        // States
                    Severity: Minor
                    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.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

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

                    ve.ui.MWGalleryDialog.prototype.toggleSearchPanel = function ( visible ) {
                        visible = visible !== undefined ? visible : !this.searchPanelVisible;
                    
                        // If currently visible panel is an edit panel, save the input values for the highlighted item
                        if ( !this.searchPanelVisible ) {
                    Severity: Minor
                    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.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

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

                    ve.ui.MWGalleryDialog.prototype.isHighlightedItemModified = function () {
                        if ( this.highlightedItem ) {
                            if ( this.highlightedAltTextInput.getValue() !== this.highlightedItem.altText ) {
                                return true;
                            }
                    Severity: Minor
                    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.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

                    Avoid too many return statements within this function.
                    Open

                                    return true;
                    Severity: Major
                    Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return false;
                      Severity: Major
                      Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js - About 30 mins to fix

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

                            this.highlightedCaptionTarget = ve.init.target.createTargetWidget( {
                                includeCommands: this.constructor.static.includeCommands,
                                excludeCommands: this.constructor.static.excludeCommands,
                                importRules: this.constructor.static.getImportRules(),
                                multiline: false
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 2 hrs to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js on lines 288..293

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

                        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

                            this.captionTarget = ve.init.target.createTargetWidget( {
                                includeCommands: this.constructor.static.includeCommands,
                                excludeCommands: this.constructor.static.excludeCommands,
                                importRules: this.constructor.static.getImportRules(),
                                multiline: false
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 2 hrs to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js on lines 222..227

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

                        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

                        ve.ui.MWGalleryDialog = function VeUiMWGalleryDialog() {
                            // Parent constructor
                            ve.ui.MWGalleryDialog.super.apply( this, arguments );
                        
                            this.$element.addClass( 've-ui-mwGalleryDialog' );
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 1 hr to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWPreDialog.js on lines 17..22

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

                        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

                            this.widthsInput = new OO.ui.NumberInputWidget( {
                                min: 0,
                                showButtons: false,
                                input: {
                                    placeholder: ve.msg( 'visualeditor-mwgallerydialog-widths-input-placeholder', this.defaults.imageWidth )
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 1 hr to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js on lines 301..307

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

                        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

                            this.heightsInput = new OO.ui.NumberInputWidget( {
                                min: 0,
                                showButtons: false,
                                input: {
                                    placeholder: ve.msg( 'visualeditor-mwgallerydialog-heights-input-placeholder', this.defaults.imageHeight )
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 1 hr to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js on lines 294..300

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

                        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

                        ve.ui.MWGalleryDialog.prototype.updateActions = function () {
                            this.actions.setAbilities( { done: this.isSaveable() } );
                        };
                        Severity: Major
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 1 hr to fix
                        modules/ve-mw/ui/ve.ui.MWExtensionWindow.js on lines 161..163

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

                        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

                                surfaceModel.change(
                                    ve.dm.TransactionBuilder.static.newFromAttributeChanges(
                                        surfaceModelDocument,
                                        this.selectedNode.getOuterRange().start,
                                        { mw: mwData }
                        Severity: Minor
                        Found in modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js and 1 other location - About 55 mins to fix
                        modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js on lines 95..99

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

                        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