Code Duplication    Length = 15-18 lines in 2 locations

src/Charcoal/Property/ModelStructureProperty.php 2 locations

@@ 453-470 (lines=18) @@
450
     * @return ArrayAccess|DescribableInterface|mixed
451
     * @throws UnexpectedValueException If the structure is invalid.
452
     */
453
    public function toModel($model = null)
454
    {
455
        if ($model) {
456
            $structure = $this->structureModelFactory()->create($model);
457
458
            if (!$structure instanceof ArrayAccess) {
459
                throw new UnexpectedValueException(sprintf(
460
                    'Structure [%s] must implement [%s]',
461
                    $model,
462
                    ArrayAccess::class
463
                ));
464
            }
465
466
            return $structure;
467
        }
468
469
        return $this->structureProto();
470
    }
471
472
    /**
473
     * PropertyInterface::save().
@@ 595-609 (lines=15) @@
592
     * @throws UnexpectedValueException If the structure is invalid.
593
     * @return ArrayAccess
594
     */
595
    private function createStructureModel()
596
    {
597
        $structClass = $this->getStructureModelClass();
598
        $structure   = $this->structureModelFactory()->create($structClass);
599
600
        if (!$structure instanceof ArrayAccess) {
601
            throw new UnexpectedValueException(sprintf(
602
                'Structure [%s] must implement [%s]',
603
                $structClass,
604
                ArrayAccess::class
605
            ));
606
        }
607
608
        return $structure;
609
    }
610
611
    /**
612
     * Create a data-model structure.