Code Duplication    Length = 21-22 lines in 2 locations

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

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