Code Duplication    Length = 21-22 lines in 2 locations

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

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