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

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