Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2276-2296 (lines=21) @@
2273
     * @param object $document
2274
     * @param array $visited
2275
     */
2276
    private function cascadeDetach($document, array &$visited)
2277
    {
2278
        $class = $this->dm->getClassMetadata(get_class($document));
2279
        foreach ($class->fieldMappings as $mapping) {
2280
            if ( ! $mapping['isCascadeDetach']) {
2281
                continue;
2282
            }
2283
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2284
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2285
                if ($relatedDocuments instanceof PersistentCollection) {
2286
                    // Unwrap so that foreach() does not initialize
2287
                    $relatedDocuments = $relatedDocuments->unwrap();
2288
                }
2289
                foreach ($relatedDocuments as $relatedDocument) {
2290
                    $this->doDetach($relatedDocument, $visited);
2291
                }
2292
            } elseif ($relatedDocuments !== null) {
2293
                $this->doDetach($relatedDocuments, $visited);
2294
            }
2295
        }
2296
    }
2297
    /**
2298
     * Cascades a merge operation to associated documents.
2299
     *
@@ 2396-2417 (lines=22) @@
2393
     * @param object $document
2394
     * @param array $visited
2395
     */
2396
    private function cascadeRemove($document, array &$visited)
2397
    {
2398
        $class = $this->dm->getClassMetadata(get_class($document));
2399
        foreach ($class->fieldMappings as $mapping) {
2400
            if ( ! $mapping['isCascadeRemove']) {
2401
                continue;
2402
            }
2403
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2404
                $document->__load();
2405
            }
2406
2407
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2408
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2409
                // If its a PersistentCollection initialization is intended! No unwrap!
2410
                foreach ($relatedDocuments as $relatedDocument) {
2411
                    $this->doRemove($relatedDocument, $visited);
2412
                }
2413
            } elseif ($relatedDocuments !== null) {
2414
                $this->doRemove($relatedDocuments, $visited);
2415
            }
2416
        }
2417
    }
2418
2419
    /**
2420
     * Acquire a lock on the given document.