Code Duplication    Length = 22-22 lines in 2 locations

lib/Mongo/MongoDB.php 1 location

@@ 320-341 (lines=22) @@
317
     * @param mixed $document_or_id
318
     * @return array Returns a database reference array.
319
     */
320
    public function createDBRef($collection, $document_or_id)
321
    {
322
        if ($document_or_id instanceof \MongoId) {
323
            $id = $document_or_id;
324
        } elseif (is_object($document_or_id)) {
325
            if (! isset($document_or_id->_id)) {
326
                return null;
327
            }
328
329
            $id = $document_or_id->_id;
330
        } elseif (is_array($document_or_id)) {
331
            if (! isset($document_or_id['_id'])) {
332
                return null;
333
            }
334
335
            $id = $document_or_id['_id'];
336
        } else {
337
            $id = $document_or_id;
338
        }
339
340
        return MongoDBRef::create($collection, $id, $this->name);
341
    }
342
343
344
    /**

lib/Mongo/MongoCollection.php 1 location

@@ 741-762 (lines=22) @@
738
     * @param array|object $document_or_id Object to which to create a reference.
739
     * @return array Returns a database reference array.
740
     */
741
    public function createDBRef($document_or_id)
742
    {
743
        if ($document_or_id instanceof \MongoId) {
744
            $id = $document_or_id;
745
        } elseif (is_object($document_or_id)) {
746
            if (! isset($document_or_id->_id)) {
747
                return null;
748
            }
749
750
            $id = $document_or_id->_id;
751
        } elseif (is_array($document_or_id)) {
752
            if (! isset($document_or_id['_id'])) {
753
                return null;
754
            }
755
756
            $id = $document_or_id['_id'];
757
        } else {
758
            $id = $document_or_id;
759
        }
760
761
        return MongoDBRef::create($this->name, $id);
762
    }
763
764
    /**
765
     * Fetches the document pointed to by a database reference