Code Duplication    Length = 21-22 lines in 2 locations

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

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