Code Duplication    Length = 21-22 lines in 2 locations

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

@@ 2112-2132 (lines=21) @@
2109
     * @param object $document
2110
     * @param array $visited
2111
     */
2112
    private function cascadeDetach($document, array &$visited)
2113
    {
2114
        $class = $this->dm->getClassMetadata(get_class($document));
2115
        foreach ($class->fieldMappings as $mapping) {
2116
            if ( ! $mapping['isCascadeDetach']) {
2117
                continue;
2118
            }
2119
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2120
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
2121
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
2122
                    // Unwrap so that foreach() does not initialize
2123
                    $relatedDocuments = $relatedDocuments->unwrap();
2124
                }
2125
                foreach ($relatedDocuments as $relatedDocument) {
2126
                    $this->doDetach($relatedDocument, $visited);
2127
                }
2128
            } elseif ($relatedDocuments !== null) {
2129
                $this->doDetach($relatedDocuments, $visited);
2130
            }
2131
        }
2132
    }
2133
    /**
2134
     * Cascades a merge operation to associated documents.
2135
     *
@@ 2227-2248 (lines=22) @@
2224
     * @param object $document
2225
     * @param array $visited
2226
     */
2227
    private function cascadeRemove($document, array &$visited)
2228
    {
2229
        $class = $this->dm->getClassMetadata(get_class($document));
2230
        foreach ($class->fieldMappings as $mapping) {
2231
            if ( ! $mapping['isCascadeRemove']) {
2232
                continue;
2233
            }
2234
            if ($document instanceof Proxy && ! $document->__isInitialized__) {
2235
                $document->__load();
2236
            }
2237
2238
            $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document);
2239
            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
2240
                // If its a PersistentCollection initialization is intended! No unwrap!
2241
                foreach ($relatedDocuments as $relatedDocument) {
2242
                    $this->doRemove($relatedDocument, $visited);
2243
                }
2244
            } elseif ($relatedDocuments !== null) {
2245
                $this->doRemove($relatedDocuments, $visited);
2246
            }
2247
        }
2248
    }
2249
2250
    /**
2251
     * Acquire a lock on the given document.