Code Duplication    Length = 22-22 lines in 2 locations

lib/Mongo/MongoDB.php 1 location

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

lib/Mongo/MongoCollection.php 1 location

@@ 673-694 (lines=22) @@
670
     * @param array|object $document_or_id Object to which to create a reference.
671
     * @return array Returns a database reference array.
672
     */
673
    public function createDBRef($document_or_id)
674
    {
675
        if ($document_or_id instanceof \MongoId) {
676
            $id = $document_or_id;
677
        } elseif (is_object($document_or_id)) {
678
            if (! isset($document_or_id->_id)) {
679
                return null;
680
            }
681
682
            $id = $document_or_id->_id;
683
        } elseif (is_array($document_or_id)) {
684
            if (! isset($document_or_id['_id'])) {
685
                return null;
686
            }
687
688
            $id = $document_or_id['_id'];
689
        } else {
690
            $id = $document_or_id;
691
        }
692
693
        return MongoDBRef::create($this->name, $id);
694
    }
695
696
    /**
697
     * Fetches the document pointed to by a database reference