Code Duplication    Length = 21-22 lines in 2 locations

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

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