Code Duplication    Length = 21-22 lines in 2 locations

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

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