Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2087-2107 (lines=21) @@
2084
     * @param object $document
2085
     * @param array $visited
2086
     */
2087
    private function cascadeDetach($document, array &$visited)
2088
    {
2089
        $class = $this->dm->getClassMetadata(get_class($document));
2090
        foreach ($class->fieldMappings as $mapping) {
2091
            if ( ! $mapping['isCascadeDetach']) {
2092
                continue;
2093
            }
2094
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2095
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2096
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
2097
                    // Unwrap so that foreach() does not initialize
2098
                    $relatedDocuments = $relatedDocuments->unwrap();
2099
                }
2100
                foreach ($relatedDocuments as $relatedDocument) {
2101
                    $this->doDetach($relatedDocument, $visited);
2102
                }
2103
            } elseif ($relatedDocuments !== null) {
2104
                $this->doDetach($relatedDocuments, $visited);
2105
            }
2106
        }
2107
    }
2108
    /**
2109
     * Cascades a merge operation to associated documents.
2110
     *
@@ 2207-2228 (lines=22) @@
2204
     * @param object $document
2205
     * @param array $visited
2206
     */
2207
    private function cascadeRemove($document, array &$visited)
2208
    {
2209
        $class = $this->dm->getClassMetadata(get_class($document));
2210
        foreach ($class->fieldMappings as $mapping) {
2211
            if ( ! $mapping['isCascadeRemove']) {
2212
                continue;
2213
            }
2214
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2215
                $document->__load();
2216
            }
2217
2218
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2219
            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
2220
                // If its a PersistentCollection initialization is intended! No unwrap!
2221
                foreach ($relatedDocuments as $relatedDocument) {
2222
                    $this->doRemove($relatedDocument, $visited);
2223
                }
2224
            } elseif ($relatedDocuments !== null) {
2225
                $this->doRemove($relatedDocuments, $visited);
2226
            }
2227
        }
2228
    }
2229
2230
    /**
2231
     * Acquire a lock on the given document.