Code Duplication    Length = 20-21 lines in 2 locations

lib/Doctrine/ODM/CouchDB/UnitOfWork.php 2 locations

@@ 686-706 (lines=21) @@
683
     * @param object $document
684
     * @param array $visited
685
     */
686
    private function cascadeDetach($document, array &$visited)
687
    {
688
        $class = $this->dm->getClassMetadata(get_class($document));
689
        foreach ($class->associationsMappings as $assoc) {
690
            if ( $assoc['cascade'] & ClassMetadata::CASCADE_DETACH == 0) {
691
                continue;
692
            }
693
            $relatedDocuments = $class->reflFields[$assoc['fieldName']]->getValue($document);
694
            if ($relatedDocuments instanceof Collection) {
695
                if ($relatedDocuments instanceof PersistentCollection) {
696
                    // Unwrap so that foreach() does not initialize
697
                    $relatedDocuments = $relatedDocuments->unwrap();
698
                }
699
                foreach ($relatedDocuments as $relatedDocument) {
700
                    $this->doDetach($relatedDocument, $visited);
701
                }
702
            } else if ($relatedDocuments !== null) {
703
                $this->doDetach($relatedDocuments, $visited);
704
            }
705
        }
706
    }
707
708
    private function cascadeRefresh($document, &$visited)
709
    {
@@ 708-727 (lines=20) @@
705
        }
706
    }
707
708
    private function cascadeRefresh($document, &$visited)
709
    {
710
        $class = $this->dm->getClassMetadata(get_class($document));
711
        foreach ($class->associationsMappings as $assoc) {
712
            if ($assoc['cascade'] & ClassMetadata::CASCADE_REFRESH) {
713
                $related = $class->reflFields[$assoc['fieldName']]->getValue($document);
714
                if ($related instanceof Collection) {
715
                    if ($related instanceof PersistentCollection) {
716
                        // Unwrap so that foreach() does not initialize
717
                        $related = $related->unwrap();
718
                    }
719
                    foreach ($related as $relatedDocument) {
720
                        $this->doRefresh($relatedDocument, $visited);
721
                    }
722
                } else if ($related !== null) {
723
                    $this->doRefresh($related, $visited);
724
                }
725
            }
726
        }
727
    }
728
729
    /**
730
     * Get the state of a document.