Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2073-2093 (lines=21) @@
2070
     * @param object $document
2071
     * @param array $visited
2072
     */
2073
    private function cascadeDetach($document, array &$visited)
2074
    {
2075
        $class = $this->dm->getClassMetadata(get_class($document));
2076
        foreach ($class->fieldMappings as $mapping) {
2077
            if ( ! $mapping['isCascadeDetach']) {
2078
                continue;
2079
            }
2080
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2081
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2082
                if ($relatedDocuments instanceof PersistentCollection) {
2083
                    // Unwrap so that foreach() does not initialize
2084
                    $relatedDocuments = $relatedDocuments->unwrap();
2085
                }
2086
                foreach ($relatedDocuments as $relatedDocument) {
2087
                    $this->doDetach($relatedDocument, $visited);
2088
                }
2089
            } elseif ($relatedDocuments !== null) {
2090
                $this->doDetach($relatedDocuments, $visited);
2091
            }
2092
        }
2093
    }
2094
    /**
2095
     * Cascades a merge operation to associated documents.
2096
     *
@@ 2193-2214 (lines=22) @@
2190
     * @param object $document
2191
     * @param array $visited
2192
     */
2193
    private function cascadeRemove($document, array &$visited)
2194
    {
2195
        $class = $this->dm->getClassMetadata(get_class($document));
2196
        foreach ($class->fieldMappings as $mapping) {
2197
            if ( ! $mapping['isCascadeRemove']) {
2198
                continue;
2199
            }
2200
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2201
                $document->__load();
2202
            }
2203
2204
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2205
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2206
                // If its a PersistentCollection initialization is intended! No unwrap!
2207
                foreach ($relatedDocuments as $relatedDocument) {
2208
                    $this->doRemove($relatedDocument, $visited);
2209
                }
2210
            } elseif ($relatedDocuments !== null) {
2211
                $this->doRemove($relatedDocuments, $visited);
2212
            }
2213
        }
2214
    }
2215
2216
    /**
2217
     * Acquire a lock on the given document.