Code Duplication    Length = 21-22 lines in 2 locations

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

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