Code Duplication    Length = 17-21 lines in 4 locations

core/libraries/rest_api/ModelDataTranslator.php 4 locations

@@ 370-386 (lines=17) @@
367
            }
368
            if ($field instanceof EE_Model_Field_Base) {
369
                if (! $writing && is_array($query_param_value)) {
370
                    if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) {
371
                        if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
372
                            throw new RestException(
373
                                'numerically_indexed_array_of_values_only',
374
                                sprintf(
375
                                    esc_html__(
376
                                        'The array provided for the parameter "%1$s" should be numerically indexed.',
377
                                        'event_espresso'
378
                                    ),
379
                                    $query_param_key
380
                                ),
381
                                array(
382
                                    'status' => 400,
383
                                )
384
                            );
385
                        }
386
                    }
387
                    //did they specify an operator?
388
                    if (isset($query_param_value[0])
389
                        && isset($valid_operators[$query_param_value[0]])
@@ 450-468 (lines=19) @@
447
                                $requested_version,
448
                                $timezone
449
                            );
450
                        } else {
451
                            //so they provided a valid operator, but wrong number of arguments
452
                            if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
453
                                throw new RestException(
454
                                    'wrong_number_of_arguments',
455
                                    sprintf(
456
                                        esc_html__(
457
                                            'The operator you provided, "%1$s" had the wrong number of arguments',
458
                                            'event_espresso'
459
                                        ),
460
                                        $op
461
                                    ),
462
                                    array(
463
                                        'status' => 400,
464
                                    )
465
                                );
466
                            }
467
                            $translated_value = null;
468
                        }
469
                    } else {
470
                        //so they didn't provide a valid operator
471
                        if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
@@ 469-489 (lines=21) @@
466
                            }
467
                            $translated_value = null;
468
                        }
469
                    } else {
470
                        //so they didn't provide a valid operator
471
                        if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
472
                            throw new RestException(
473
                                'invalid_operator',
474
                                sprintf(
475
                                    esc_html__(
476
                                        'You provided an invalid parameter, with key "%1$s" and value "%2$s"',
477
                                        'event_espresso'
478
                                    ),
479
                                    $query_param_key,
480
                                    $query_param_value
481
                                ),
482
                                array(
483
                                    'status' => 400,
484
                                )
485
                            );
486
                        }
487
                        //if we aren't in debug mode, then just try our best to fulfill the user's request
488
                        $translated_value = null;
489
                    }
490
                } else {
491
                    $translated_value = ModelDataTranslator::prepareFieldValueFromJson(
492
                        $field,
@@ 532-548 (lines=17) @@
529
                            $model,
530
                            $requested_version
531
                        );
532
                    } elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
533
                        //only tell API clients they got it wrong if we're in debug mode
534
                        //otherwise try our best ot fulfill their request by ignoring this invalid data
535
                        throw new RestException(
536
                            'invalid_parameter',
537
                            sprintf(
538
                                esc_html__(
539
                                    'You provided an invalid parameter, with key "%1$s"',
540
                                    'event_espresso'
541
                                ),
542
                                $query_param_sans_stars
543
                            ),
544
                            array(
545
                                'status' => 400,
546
                            )
547
                        );
548
                    }
549
                }
550
            }
551
        }