Code Duplication    Length = 13-13 lines in 2 locations

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

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