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

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