Code Duplication    Length = 15-15 lines in 2 locations

src/Denormalizer/CollectionFieldDenormalizer.php 1 location

@@ 64-78 (lines=15) @@
61
        $existingChildObjects = $this->accessor->getValue($object) ?? [];
62
63
        $newChildObjects = [];
64
        foreach ($value as $i => $subValue) {
65
            $subPath = $path.'['.$i.']';
66
67
            if (!is_array($subValue)) {
68
                throw DeserializerRuntimeException::createInvalidDataType($subPath, gettype($subValue), 'array');
69
            }
70
71
            if (isset($existingChildObjects[$i])) {
72
                $newChildObject = $existingChildObjects[$i];
73
            } else {
74
                $newChildObject = $this->class;
75
            }
76
77
            $newChildObjects[$i] = $denormalizer->denormalize($newChildObject, $subValue, $context, $subPath);
78
        }
79
80
        $this->accessor->setValue($object, $newChildObjects);
81
    }

src/Denormalizer/Relation/EmbedManyFieldDenormalizer.php 1 location

@@ 70-84 (lines=15) @@
67
        $existingChildObjects = $this->accessor->getValue($object) ?? [];
68
69
        $newChildObjects = [];
70
        foreach ($value as $i => $subValue) {
71
            $subPath = $path.'['.$i.']';
72
73
            if (!is_array($subValue)) {
74
                throw DeserializerRuntimeException::createInvalidDataType($subPath, gettype($subValue), 'array');
75
            }
76
77
            if (isset($existingChildObjects[$i])) {
78
                $newChildObject = $existingChildObjects[$i];
79
            } else {
80
                $newChildObject = $this->class;
81
            }
82
83
            $newChildObjects[$i] = $denormalizer->denormalize($newChildObject, $subValue, $context, $subPath);
84
        }
85
86
        $this->accessor->setValue($object, $newChildObjects);
87
    }