Code Duplication    Length = 22-22 lines in 2 locations

lib/Mongo/MongoDB.php 1 location

@@ 305-326 (lines=22) @@
302
     * @param mixed $document_or_id
303
     * @return array Returns a database reference array.
304
     */
305
    public function createDBRef($collection, $document_or_id)
306
    {
307
        if ($document_or_id instanceof \MongoId) {
308
            $id = $document_or_id;
309
        } elseif (is_object($document_or_id)) {
310
            if (! isset($document_or_id->_id)) {
311
                return null;
312
            }
313
314
            $id = $document_or_id->_id;
315
        } elseif (is_array($document_or_id)) {
316
            if (! isset($document_or_id['_id'])) {
317
                return null;
318
            }
319
320
            $id = $document_or_id['_id'];
321
        } else {
322
            $id = $document_or_id;
323
        }
324
325
        return MongoDBRef::create($collection, $id, $this->name);
326
    }
327
328
329
    /**

lib/Mongo/MongoCollection.php 1 location

@@ 603-624 (lines=22) @@
600
     * @param array|object $document_or_id Object to which to create a reference.
601
     * @return array Returns a database reference array.
602
     */
603
    public function createDBRef($document_or_id)
604
    {
605
        if ($document_or_id instanceof \MongoId) {
606
            $id = $document_or_id;
607
        } elseif (is_object($document_or_id)) {
608
            if (! isset($document_or_id->_id)) {
609
                return null;
610
            }
611
612
            $id = $document_or_id->_id;
613
        } elseif (is_array($document_or_id)) {
614
            if (! isset($document_or_id['_id'])) {
615
                return null;
616
            }
617
618
            $id = $document_or_id['_id'];
619
        } else {
620
            $id = $document_or_id;
621
        }
622
623
        return MongoDBRef::create($this->name, $id);
624
    }
625
626
    /**
627
     * Fetches the document pointed to by a database reference