felixarntz/plugin-lib

View on GitHub
assets/src/js/fields.js

Summary

Maintainability
F
3 mos
Test Coverage

File fields.js has 1303 lines of code (exceeds 250 allowed). Consider refactoring.
Open

( function( exports, $, _, Backbone, wp, fieldsAPIData ) {
    'use strict';

    _.mixin({
        alias: function( alias, func ) {
Severity: Major
Found in assets/src/js/fields.js - About 3 days to fix

    Function postRender has 113 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            postRender: function( $el ) {
                var $hidden = $el.find( '.plugin-lib-control' ).prev();
                var store   = $el.find( '.plugin-lib-control' ).data( 'store' );
                var options = {
                    closeOnDateSelect: true,
    Severity: Major
    Found in assets/src/js/fields.js - About 4 hrs to fix

      Function get_data_by_named_map has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              'get_data_by_named_map': function( prop, values, args, cb, instanceId ) {
                  var defaultResult = args['default'] || null;
      
                  if ( _.isUndefined( args.named_map ) || _.isEmpty( args.named_map ) ) {
                      cb( defaultResult );
      Severity: Major
      Found in assets/src/js/fields.js - About 2 hrs to fix

        Function postRender has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                postRender: function( $el ) {
                    var autocompleteArgs = this.model.get( 'autocomplete' );
                    if ( ! autocompleteArgs ) {
                        autocompleteArgs = this.model.get( 'itemInitial' ).autocomplete;
                    }
        Severity: Major
        Found in assets/src/js/fields.js - About 2 hrs to fix

          Function getInputValue has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  getInputValue: function( $input ) {
                      var currentValue = null;
                      var dateParts;
          
                      if ( ( $input.is( ':checkbox' ) && '[]' === $input.attr( 'name' ).substr( -2 ) ) ) {
          Severity: Minor
          Found in assets/src/js/fields.js - About 1 hr to fix

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

                    constructor: function( options ) {
                        options = options || {};
            
                        var model;
            
            
            Severity: Minor
            Found in assets/src/js/fields.js - About 1 hr to fix

              Function get_data_by_condition_numeric_comparison_helper has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      'get_data_by_condition_numeric_comparison_helper': function( prop, values, args, reverse ) {
                          var operator = ( args.operator && args.operator.toUpperCase() === 'OR' ) ? 'OR' : 'AND';
              
                          var resultFalse, resultTrue, breakpoint, sanitize, inclusive, value, identifier, i;
                          if ( reverse ) {
              Severity: Minor
              Found in assets/src/js/fields.js - About 1 hr to fix

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

                        postRender: function( $el ) {
                            var editorId = $el.find( '.plugin-lib-control' ).attr( 'id' );
                            var editorData = $el.find( '.plugin-lib-control' ).data();
                            var editorSettings;
                
                
                Severity: Minor
                Found in assets/src/js/fields.js - About 1 hr to fix

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

                          'get_data_by_map': function( prop, values, args, cb ) {
                              var defaultResult = args['default'] || null;
                  
                              if ( _.isUndefined( args.map ) || _.isEmpty( args.map ) ) {
                                  cb( defaultResult );
                  Severity: Minor
                  Found in assets/src/js/fields.js - About 1 hr to fix

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

                            removeItem: function( e ) {
                                var self = this;
                    
                                var limit = this.model.get( 'repeatableLimit' );
                                var items = this.model.get( 'items' );
                    Severity: Minor
                    Found in assets/src/js/fields.js - About 1 hr to fix

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

                                  options.onShow = function( ct, $input ) {
                                      var newOptions = {};
                                      var value      = $hidden.val();
                                      var helper;
                      
                      
                      Severity: Minor
                      Found in assets/src/js/fields.js - About 1 hr to fix

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

                                        source: function( request, response ) {
                                            var restUrl = fieldsAPIData.restUrl + autocompleteArgs.restPlaceholderSearchRoute.replace( '%search%', request.term );
                                            $.ajax( restUrl, {
                                                method: 'GET',
                                                dataType: 'json',
                        Severity: Minor
                        Found in assets/src/js/fields.js - About 1 hr to fix

                          Function changeItemValue has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                  changeItemValue: function( e ) {
                                      var $itemFieldInput = this.$( e.target );
                                      var itemFieldId = $itemFieldInput.attr( 'id' );
                                      var newValue = this.getInputValue( $itemFieldInput );
                          
                          
                          Severity: Minor
                          Found in assets/src/js/fields.js - About 1 hr to fix

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

                                    'get_data_by_condition_bool_helper': function( prop, values, args, reverse ) {
                                        var operator = ( args.operator && args.operator.toUpperCase() === 'OR' ) ? 'OR' : 'AND';
                            
                                        var resultFalse, resultTrue, value, identifier, i;
                                        if ( reverse ) {
                            Severity: Minor
                            Found in assets/src/js/fields.js - About 1 hr to fix

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

                                      preRender: function( $el ) {
                                          var fields;
                              
                                          if ( this.model.get( 'repeatable' ) && _.isArray( this.model.get( 'items' ) ) ) {
                                              var itemIndex = $el.parent().children().index( $el );
                              Severity: Minor
                              Found in assets/src/js/fields.js - About 1 hr to fix

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

                                        postRender: function( $el ) {
                                            var fields;
                                
                                            if ( this.model.get( 'repeatable' ) && _.isArray( this.model.get( 'items' ) ) ) {
                                                var itemIndex = $el.parent().children().index( $el );
                                Severity: Minor
                                Found in assets/src/js/fields.js - About 1 hr to fix

                                  Function add has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                          add: function( targetId, prop, callback, values, args ) {
                                  Severity: Minor
                                  Found in assets/src/js/fields.js - About 35 mins to fix

                                    Function get_data_by_named_map has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                            'get_data_by_named_map': function( prop, values, args, cb, instanceId ) {
                                    Severity: Minor
                                    Found in assets/src/js/fields.js - About 35 mins to fix

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

                                      ( function( exports, $, _, Backbone, wp, fieldsAPIData ) {
                                          'use strict';
                                      
                                          _.mixin({
                                              alias: function( alias, func ) {
                                      Severity: Major
                                      Found in assets/src/js/fields.js and 1 other location - About 3 mos to fix
                                      assets/dist/js/fields.js on lines 6..1694

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

                                      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