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 ) {
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,
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 );
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;
}
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 ) ) ) {
Function constructor
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor: function( options ) {
options = options || {};
var model;
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 ) {
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;
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 );
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' );
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;
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',
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 );
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 ) {
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 );
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 );
Function add
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
add: function( targetId, prop, callback, values, args ) {
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 ) {
Similar blocks of code found in 2 locations. Consider refactoring. Open
( function( exports, $, _, Backbone, wp, fieldsAPIData ) {
'use strict';
_.mixin({
alias: function( alias, func ) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76