Code Duplication    Length = 21-26 lines in 2 locations

lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php 2 locations

@@ 248-273 (lines=26) @@
245
                    $mapping['fieldName'],
246
                    Type::getType($mapping['type'])->closureToPHP()
247
                );
248
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
249
                $code .= sprintf(<<<EOF
250
251
        /** @ReferenceOne */
252
        if (isset(\$data['%1\$s'])) {
253
            \$reference = \$data['%1\$s'];
254
            if (isset(\$this->class->fieldMappings['%2\$s']['simple']) && \$this->class->fieldMappings['%2\$s']['simple']) {
255
                \$className = \$this->class->fieldMappings['%2\$s']['targetDocument'];
256
                \$mongoId = \$reference;
257
            } else {
258
                \$className = \$this->unitOfWork->getClassNameForAssociation(\$this->class->fieldMappings['%2\$s'], \$reference);
259
                \$mongoId = \$reference['\$id'];
260
            }
261
            \$targetMetadata = \$this->dm->getClassMetadata(\$className);
262
            \$id = \$targetMetadata->getPHPIdentifierValue(\$mongoId);
263
            \$return = \$this->dm->getReference(\$className, \$id);
264
            \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
265
            \$hydratedData['%2\$s'] = \$return;
266
        }
267
268
EOF
269
                    ,
270
                    $mapping['name'],
271
                    $mapping['fieldName']
272
                );
273
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isInverseSide']) {
274
                if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
275
                    $code .= sprintf(<<<EOF
276
@@ 311-331 (lines=21) @@
308
                        $mapping['fieldName']
309
                    );
310
                }
311
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_MANY || $mapping['association'] === ClassMetadata::EMBED_MANY) {
312
                $code .= sprintf(<<<EOF
313
314
        /** @Many */
315
        \$mongoData = isset(\$data['%1\$s']) ? \$data['%1\$s'] : null;
316
        \$return = \$this->dm->getConfiguration()->getPersistentCollectionFactory()->create(\$this->dm, \$this->class->fieldMappings['%2\$s']);
317
        \$return->setHints(\$hints);
318
        \$return->setOwner(\$document, \$this->class->fieldMappings['%2\$s']);
319
        \$return->setInitialized(false);
320
        if (\$mongoData) {
321
            \$return->setMongoData(\$mongoData);
322
        }
323
        \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
324
        \$hydratedData['%2\$s'] = \$return;
325
326
EOF
327
                    ,
328
                    $mapping['name'],
329
                    $mapping['fieldName']
330
                );
331
            } elseif ($mapping['association'] === ClassMetadata::EMBED_ONE) {
332
                $code .= sprintf(<<<EOF
333
334
        /** @EmbedOne */