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 PersistentCollectionInterface) {
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
     *
@@ 2204-2225 (lines=22) @@
2201
     * @param object $document
2202
     * @param array $visited
2203
     */
2204
    private function cascadeRemove($document, array &$visited)
2205
    {
2206
        $class = $this->dm->getClassMetadata(get_class($document));
2207
        foreach ($class->fieldMappings as $mapping) {
2208
            if ( ! $mapping['isCascadeRemove']) {
2209
                continue;
2210
            }
2211
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2212
                $document->__load();
2213
            }
2214
2215
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2216
            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
2217
                // If its a PersistentCollection initialization is intended! No unwrap!
2218
                foreach ($relatedDocuments as $relatedDocument) {
2219
                    $this->doRemove($relatedDocument, $visited);
2220
                }
2221
            } elseif ($relatedDocuments !== null) {
2222
                $this->doRemove($relatedDocuments, $visited);
2223
            }
2224
        }
2225
    }
2226
2227
    /**
2228
     * Acquire a lock on the given document.