Code Duplication    Length = 29-29 lines in 2 locations

src/dbo/fields.php 2 locations

@@ 409-437 (lines=29) @@
406
 * <li>{@link ERROR_INTEGER_VALUE_OUT_OF_RANGE} - specified maximum length is greater than {@link MAX_FIELD_STRING}</li>
407
 * </ul>
408
 */
409
function field_validate_string ($field_name, $max_length)
410
{
411
    debug_write_log(DEBUG_TRACE, '[field_validate_string]');
412
    debug_write_log(DEBUG_DUMP,  '[field_validate_string] $field_name = ' . $field_name);
413
    debug_write_log(DEBUG_DUMP,  '[field_validate_string] $max_length = ' . $max_length);
414
415
    // Check that field name is not empty.
416
    if (ustrlen($field_name) == 0)
417
    {
418
        debug_write_log(DEBUG_NOTICE, '[field_validate_string] At least one required field is empty.');
419
        return ERROR_INCOMPLETE_FORM;
420
    }
421
422
    // Check that specified values are integer.
423
    if (!is_intvalue($max_length))
424
    {
425
        debug_write_log(DEBUG_NOTICE, '[field_validate_string] Invalid integer value.');
426
        return ERROR_INVALID_INTEGER_VALUE;
427
    }
428
429
    // Check that specified values are in the range of valid values.
430
    if ($max_length < 1 || $max_length > MAX_FIELD_STRING)
431
    {
432
        debug_write_log(DEBUG_NOTICE, '[field_validate_string] Integer value is out of range.');
433
        return ERROR_INTEGER_VALUE_OUT_OF_RANGE;
434
    }
435
436
    return NO_ERROR;
437
}
438
439
/**
440
 * Validates 'Multilined text' field information before creation or modification.
@@ 452-480 (lines=29) @@
449
 * <li>{@link ERROR_INTEGER_VALUE_OUT_OF_RANGE} - specified maximum length is greater than {@link MAX_FIELD_MULTILINED}</li>
450
 * </ul>
451
 */
452
function field_validate_multilined ($field_name, $max_length)
453
{
454
    debug_write_log(DEBUG_TRACE, '[field_validate_multilined]');
455
    debug_write_log(DEBUG_DUMP,  '[field_validate_multilined] $field_name = ' . $field_name);
456
    debug_write_log(DEBUG_DUMP,  '[field_validate_multilined] $max_length = ' . $max_length);
457
458
    // Check that field name is not empty.
459
    if (ustrlen($field_name) == 0)
460
    {
461
        debug_write_log(DEBUG_NOTICE, '[field_validate_multilined] At least one required field is empty.');
462
        return ERROR_INCOMPLETE_FORM;
463
    }
464
465
    // Check that specified values are integer.
466
    if (!is_intvalue($max_length))
467
    {
468
        debug_write_log(DEBUG_NOTICE, '[field_validate_multilined] Invalid integer value.');
469
        return ERROR_INVALID_INTEGER_VALUE;
470
    }
471
472
    // Check that specified values are in the range of valid values.
473
    if ($max_length < 1 || $max_length > MAX_FIELD_MULTILINED)
474
    {
475
        debug_write_log(DEBUG_NOTICE, '[field_validate_multilined] Integer value is out of range.');
476
        return ERROR_INTEGER_VALUE_OUT_OF_RANGE;
477
    }
478
479
    return NO_ERROR;
480
}
481
482
/**
483
 * Validates 'Date' field information before creation or modification.