Code Duplication    Length = 21-22 lines in 2 locations

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

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