Code Duplication    Length = 22-22 lines in 2 locations

lib/Mongo/MongoDB.php 1 location

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

lib/Mongo/MongoCollection.php 1 location

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