Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2075-2095 (lines=21) @@
2072
     * @param object $document
2073
     * @param array $visited
2074
     */
2075
    private function cascadeDetach($document, array &$visited)
2076
    {
2077
        $class = $this->dm->getClassMetadata(get_class($document));
2078
        foreach ($class->fieldMappings as $mapping) {
2079
            if ( ! $mapping['isCascadeDetach']) {
2080
                continue;
2081
            }
2082
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2083
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2084
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
2085
                    // Unwrap so that foreach() does not initialize
2086
                    $relatedDocuments = $relatedDocuments->unwrap();
2087
                }
2088
                foreach ($relatedDocuments as $relatedDocument) {
2089
                    $this->doDetach($relatedDocument, $visited);
2090
                }
2091
            } elseif ($relatedDocuments !== null) {
2092
                $this->doDetach($relatedDocuments, $visited);
2093
            }
2094
        }
2095
    }
2096
    /**
2097
     * Cascades a merge operation to associated documents.
2098
     *
@@ 2190-2211 (lines=22) @@
2187
     * @param object $document
2188
     * @param array $visited
2189
     */
2190
    private function cascadeRemove($document, array &$visited)
2191
    {
2192
        $class = $this->dm->getClassMetadata(get_class($document));
2193
        foreach ($class->fieldMappings as $mapping) {
2194
            if ( ! $mapping['isCascadeRemove']) {
2195
                continue;
2196
            }
2197
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2198
                $document->__load();
2199
            }
2200
2201
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2202
            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
2203
                // If its a PersistentCollection initialization is intended! No unwrap!
2204
                foreach ($relatedDocuments as $relatedDocument) {
2205
                    $this->doRemove($relatedDocument, $visited);
2206
                }
2207
            } elseif ($relatedDocuments !== null) {
2208
                $this->doRemove($relatedDocuments, $visited);
2209
            }
2210
        }
2211
    }
2212
2213
    /**
2214
     * Acquire a lock on the given document.