Code Duplication    Length = 22-22 lines in 2 locations

lib/Mongo/MongoDB.php 1 location

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

lib/Mongo/MongoCollection.php 1 location

@@ 690-711 (lines=22) @@
687
     * @param array|object $document_or_id Object to which to create a reference.
688
     * @return array Returns a database reference array.
689
     */
690
    public function createDBRef($document_or_id)
691
    {
692
        if ($document_or_id instanceof \MongoId) {
693
            $id = $document_or_id;
694
        } elseif (is_object($document_or_id)) {
695
            if (! isset($document_or_id->_id)) {
696
                return null;
697
            }
698
699
            $id = $document_or_id->_id;
700
        } elseif (is_array($document_or_id)) {
701
            if (! isset($document_or_id['_id'])) {
702
                return null;
703
            }
704
705
            $id = $document_or_id['_id'];
706
        } else {
707
            $id = $document_or_id;
708
        }
709
710
        return MongoDBRef::create($this->name, $id);
711
    }
712
713
    /**
714
     * Fetches the document pointed to by a database reference