Code Duplication    Length = 13-13 lines in 2 locations

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php 2 locations

@@ 234-246 (lines=13) @@
231
            $data = $this->pb->prepareInsertData($document);
232
233
            // Set the initial version for each insert
234
            if ($this->class->isVersioned) {
235
                $versionMapping = $this->class->fieldMappings[$this->class->versionField];
236
                $nextVersion = null;
237
                if ($versionMapping['type'] === 'int') {
238
                    $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
239
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
240
                } elseif ($versionMapping['type'] === 'date') {
241
                    $nextVersionDateTime = new \DateTime();
242
                    $nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
243
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
244
                }
245
                $data[$versionMapping['name']] = $nextVersion;
246
            }
247
248
            $inserts[] = $data;
249
        }
@@ 313-325 (lines=13) @@
310
        $data = $this->pb->prepareUpsertData($document);
311
312
        // Set the initial version for each upsert
313
        if ($this->class->isVersioned) {
314
            $versionMapping = $this->class->fieldMappings[$this->class->versionField];
315
            $nextVersion = null;
316
            if ($versionMapping['type'] === 'int') {
317
                $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
318
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
319
            } elseif ($versionMapping['type'] === 'date') {
320
                $nextVersionDateTime = new \DateTime();
321
                $nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
322
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
323
            }
324
            $data['$set'][$versionMapping['name']] = $nextVersion;
325
        }
326
327
        foreach (array_keys($criteria) as $field) {
328
            unset($data['$set'][$field]);