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

@@ 757-778 (lines=22) @@
754
     * @param array|object $document_or_id Object to which to create a reference.
755
     * @return array Returns a database reference array.
756
     */
757
    public function createDBRef($document_or_id)
758
    {
759
        if ($document_or_id instanceof \MongoId) {
760
            $id = $document_or_id;
761
        } elseif (is_object($document_or_id)) {
762
            if (! isset($document_or_id->_id)) {
763
                return null;
764
            }
765
766
            $id = $document_or_id->_id;
767
        } elseif (is_array($document_or_id)) {
768
            if (! isset($document_or_id['_id'])) {
769
                return null;
770
            }
771
772
            $id = $document_or_id['_id'];
773
        } else {
774
            $id = $document_or_id;
775
        }
776
777
        return MongoDBRef::create($this->name, $id);
778
    }
779
780
    /**
781
     * Fetches the document pointed to by a database reference