Code Duplication    Length = 21-22 lines in 2 locations

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

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