Code Duplication    Length = 21-22 lines in 2 locations

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

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