Code Duplication    Length = 21-22 lines in 2 locations

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

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