Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2081-2101 (lines=21) @@
2078
     * @param object $document
2079
     * @param array $visited
2080
     */
2081
    private function cascadeDetach($document, array &$visited)
2082
    {
2083
        $class = $this->dm->getClassMetadata(get_class($document));
2084
        foreach ($class->fieldMappings as $mapping) {
2085
            if ( ! $mapping['isCascadeDetach']) {
2086
                continue;
2087
            }
2088
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2089
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2090
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
2091
                    // Unwrap so that foreach() does not initialize
2092
                    $relatedDocuments = $relatedDocuments->unwrap();
2093
                }
2094
                foreach ($relatedDocuments as $relatedDocument) {
2095
                    $this->doDetach($relatedDocument, $visited);
2096
                }
2097
            } elseif ($relatedDocuments !== null) {
2098
                $this->doDetach($relatedDocuments, $visited);
2099
            }
2100
        }
2101
    }
2102
    /**
2103
     * Cascades a merge operation to associated documents.
2104
     *
@@ 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.