Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2101-2121 (lines=21) @@
2098
     * @param object $document
2099
     * @param array $visited
2100
     */
2101
    private function cascadeDetach($document, array &$visited)
2102
    {
2103
        $class = $this->dm->getClassMetadata(get_class($document));
2104
        foreach ($class->fieldMappings as $mapping) {
2105
            if ( ! $mapping['isCascadeDetach']) {
2106
                continue;
2107
            }
2108
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2109
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2110
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
2111
                    // Unwrap so that foreach() does not initialize
2112
                    $relatedDocuments = $relatedDocuments->unwrap();
2113
                }
2114
                foreach ($relatedDocuments as $relatedDocument) {
2115
                    $this->doDetach($relatedDocument, $visited);
2116
                }
2117
            } elseif ($relatedDocuments !== null) {
2118
                $this->doDetach($relatedDocuments, $visited);
2119
            }
2120
        }
2121
    }
2122
    /**
2123
     * Cascades a merge operation to associated documents.
2124
     *
@@ 2216-2237 (lines=22) @@
2213
     * @param object $document
2214
     * @param array $visited
2215
     */
2216
    private function cascadeRemove($document, array &$visited)
2217
    {
2218
        $class = $this->dm->getClassMetadata(get_class($document));
2219
        foreach ($class->fieldMappings as $mapping) {
2220
            if ( ! $mapping['isCascadeRemove']) {
2221
                continue;
2222
            }
2223
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2224
                $document->__load();
2225
            }
2226
2227
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2228
            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
2229
                // If its a PersistentCollection initialization is intended! No unwrap!
2230
                foreach ($relatedDocuments as $relatedDocument) {
2231
                    $this->doRemove($relatedDocument, $visited);
2232
                }
2233
            } elseif ($relatedDocuments !== null) {
2234
                $this->doRemove($relatedDocuments, $visited);
2235
            }
2236
        }
2237
    }
2238
2239
    /**
2240
     * Acquire a lock on the given document.