Code Duplication    Length = 29-29 lines in 2 locations

src/Charcoal/Cms/AbstractSection.php 1 location

@@ 469-497 (lines=29) @@
466
     * @param  string|PropertyInterface $separator The boundary string.
467
     * @return array
468
     */
469
    public function parseAsMultiple($value, $separator = ',')
470
    {
471
        if (!isset($value) ||
472
            (is_string($value) && !strlen(trim($value))) ||
473
            (is_array($value) && !count(array_filter($value, 'strlen')))
474
        ) {
475
            return [];
476
        }
477
478
        /**
479
         * This property is marked as "multiple".
480
         * Manually handling the resolution to array
481
         * until the property itself manages this.
482
         */
483
        if (is_string($value)) {
484
            return explode($separator, $value);
485
        }
486
487
        /**
488
         * If the parameter isn't an array yet,
489
         * means we might be dealing with an integer,
490
         * an empty string, or an object.
491
         */
492
        if (!is_array($value)) {
493
            return [ $value ];
494
        }
495
496
        return $value;
497
    }
498
499
    // ==========================================================================
500
    // EVENTS

src/Charcoal/Cms/AbstractNews.php 1 location

@@ 390-418 (lines=29) @@
387
     * @param  string|PropertyInterface $separator The boundary string.
388
     * @return array
389
     */
390
    public function parseAsMultiple($value, $separator = ',')
391
    {
392
        if (!isset($value) ||
393
            (is_string($value) && !strlen(trim($value))) ||
394
            (is_array($value) && !count(array_filter($value, 'strlen')))
395
        ) {
396
            return [];
397
        }
398
399
        /**
400
         * This property is marked as "multiple".
401
         * Manually handling the resolution to array
402
         * until the property itself manages this.
403
         */
404
        if (is_string($value)) {
405
            return explode($separator, $value);
406
        }
407
408
        /**
409
         * If the parameter isn't an array yet,
410
         * means we might be dealing with an integer,
411
         * an empty string, or an object.
412
         */
413
        if (!is_array($value)) {
414
            return [ $value ];
415
        }
416
417
        return $value;
418
    }
419
420
    // ==========================================================================
421
    // EVENTS