aristath/kirki

View on GitHub
packages/kirki-framework/control-repeater/src/control.js

Summary

Maintainability
F
1 wk
Test Coverage

File control.js has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import "./control.scss";

/* global kirkiControlLoader */
/* eslint max-depth: 0 */
/* eslint no-useless-escape: 0 */
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js - About 1 day to fix

Function RepeaterRow has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

var RepeaterRow = function( rowIndex, container, label, control ) {
    var self        = this;
    this.rowIndex   = rowIndex;
    this.container  = container;
    this.label      = label;
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.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

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

    initKirkiControl: function( control ) {
        var limit, theNewRow, settingValue;
        control = control || this;

        // The current value set in Control Class (set in Kirki_Customize_Repeater_Control::to_json() function)
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js - About 2 hrs to fix

repeater has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

wp.customize.controlConstructor.repeater = wp.customize.Control.extend( {

    // When we're finished loading continue processing
    ready: function() {
        var control = this;
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 2 hrs to fix

Function RepeaterRow has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var RepeaterRow = function( rowIndex, container, label, control ) {
    var self        = this;
    this.rowIndex   = rowIndex;
    this.container  = container;
    this.label      = label;
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js - About 2 hrs to fix

Function addRow has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    addRow: function( data ) {
        var control       = this,
            template      = control.repeaterTemplate(), // The template for the new row (defined on Kirki_Customize_Repeater_Control::render_content() ).
            settingValue  = this.getValue(), // Get the current setting value.
            newRowSetting = {}, // Saves the new setting data.
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.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 calculateImageSelectOptions has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    calculateImageSelectOptions: function( attachment, controller ) {
        var control    = controller.get( 'control' ),
            flexWidth  = !! parseInt( control.params.flex_width, 10 ),
            flexHeight = !! parseInt( control.params.flex_height, 10 ),
            realWidth  = attachment.get( 'width' ),
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 1 hr to fix

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

    addRow: function( data ) {
        var control       = this,
            template      = control.repeaterTemplate(), // The template for the new row (defined on Kirki_Customize_Repeater_Control::render_content() ).
            settingValue  = this.getValue(), // Get the current setting value.
            newRowSetting = {}, // Saves the new setting data.
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 1 hr to fix

Function initCropperFrame has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    initCropperFrame: function() {

        // We get the field id from which this was called
        var currentFieldId = this.$thisButton.siblings( 'input.hidden-field' ).attr( 'data-field' ),
            attrs          = [ 'width', 'height', 'flex_width', 'flex_height' ], // A list of attributes to look for
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 1 hr to fix

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

    this.updateLabel = function() {
        var rowLabelField,
            rowLabel,
            rowLabelSelector;

Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 1 hr to fix

Function mustBeCropped has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    mustBeCropped: function( flexW, flexH, dstW, dstH, imgW, imgH ) {
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                        if ( ! _.isUndefined( control.params.fields[ this.label.field ].type ) ) {
                            if ( 'select' === control.params.fields[ this.label.field ].type ) {
                                if ( ! _.isUndefined( control.params.fields[ this.label.field ].choices ) && ! _.isUndefined( control.params.fields[ this.label.field ].choices[ rowLabelField.val() ] ) ) {
                                    rowLabel = control.params.fields[ this.label.field ].choices[ rowLabelField.val() ];
                                }
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js - About 45 mins to fix

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

    getMimeType: function() {

        // We get the field id from which this was called
        var currentFieldId = this.$thisButton.siblings( 'input.hidden-field' ).attr( 'data-field' );

Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.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 mustBeCropped has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    mustBeCropped: function( flexW, flexH, dstW, dstH, imgW, imgH ) {
        return ! ( ( true === flexW && true === flexH ) || ( true === flexW && dstH === imgH ) || ( true === flexH && dstW === imgW ) || ( dstW === imgW && dstH === imgH ) || ( imgW <= dstW ) );
    },
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.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 deleteRow has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    deleteRow: function( index ) {
        var currentSettings = this.getValue(),
            row,
            prop;

Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js - 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

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

    removeFile: function( event ) {
        var $targetDiv,
            $uploadButton;

        if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 1 day to fix
packages/kirki-framework/control-repeater/src/control.js on lines 486..505

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

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

    removeImage: function( event ) {
        var $targetDiv,
            $uploadButton;

        if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 1 day to fix
packages/kirki-framework/control-repeater/src/control.js on lines 507..527

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

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

        control.container.on( 'click keypress', '.repeater-field-image .remove-button,.repeater-field-cropped_image .remove-button', function( e ) {
            e.preventDefault();
            control.$thisButton = jQuery( this );
            control.removeImage( e );
        } );
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 1 hr to fix
packages/kirki-framework/control-repeater/src/control.js on lines 143..147

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

        control.container.on( 'click keypress', '.repeater-field-image .upload-button,.repeater-field-cropped_image .upload-button,.repeater-field-upload .upload-button', function( e ) {
            e.preventDefault();
            control.$thisButton = jQuery( this );
            control.openFrame( e );
        } );
Severity: Major
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 1 hr to fix
packages/kirki-framework/control-repeater/src/control.js on lines 149..153

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

            var currentPicker   = jQuery( event.target ),
                row             = currentPicker.closest( '.repeater-row' ),
                rowIndex        = row.data( 'row' ),
                currentSettings = control.getValue();
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 55 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 815..818

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

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

            var currentDropdown = jQuery( event.target ),
                row             = currentDropdown.closest( '.repeater-row' ),
                rowIndex        = row.data( 'row' ),
                currentSettings = control.getValue();
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 55 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 772..775

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

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 ( _.isObject( this.params.fields[ currentFieldId ] ) && 'cropped_image' === this.params.fields[ currentFieldId ].type ) {

                //Iterate over the list of attributes
                attrs.forEach( function( el ) {

Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 35 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 473..481

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

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

        $targetDiv.find( '.kirki-image-attachment' ).html( '<img src="' + attachment.url + '">' ).hide().slideDown( 'slow' );
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 35 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 452..452

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

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 ( _.isObject( this.params.fields[ currentFieldId ] ) && 'upload' === this.params.fields[ currentFieldId ].type ) {

                // If the attribute exists in the field
                if ( ! _.isUndefined( this.params.fields[ currentFieldId ].mime_type ) ) {

Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 35 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 259..271

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

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

        $targetDiv.find( '.kirki-file-attachment' ).html( '<span class="file"><span class="dashicons dashicons-media-default"></span> ' + attachment.filename + '</span>' ).hide().slideDown( 'slow' );
Severity: Minor
Found in packages/kirki-framework/control-repeater/src/control.js and 1 other location - About 35 mins to fix
packages/kirki-framework/control-repeater/src/control.js on lines 432..432

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

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