Code Duplication    Length = 17-20 lines in 2 locations

Bundle/WidgetMapBundle/Entity/WidgetMap.php 2 locations

@@ 245-264 (lines=20) @@
242
        foreach ($positions as $position) {
243
            $children[$position] = null;
244
            if (($childs = $widgetMap->getChilds($position)) && !empty($childs)) {
245
                foreach ($childs as $_child) {
246
                    // found child must belongs to the given view or one of it's templates
247
                    if ($view) {
248
                        // if child has a view
249
                        // and child view is same as given view or the child view is a template of given view
250
                        if ($_child->getView() && ($view == $_child->getView() || $_child->getView()->isTemplateOf($view))
251
                        ) {
252
                            // if child is a substitute in view
253
                            if ($substitute = $_child->getSubstituteForView($view)) {
254
                                // if i'm not the parent of the substitute or i does not have the same position, child is not valid
255
                                if ($substitute->getParent() != $this || $substitute->getPosition() != $position) {
256
                                    $_child = null;
257
                                }
258
                            }
259
                            $children[$position] = $_child;
260
                        }
261
                    } else {
262
                        $children[$position] = $_child;
263
                    }
264
                }
265
            }
266
            // If I am replaced and my replacement has children for the position
267
            if (!$children[$position]
@@ 270-286 (lines=17) @@
267
            if (!$children[$position]
268
                && ($replaced = $this->getReplaced())
269
                && !empty($this->getReplaced()->getChilds($position))) {
270
                foreach ($this->getReplaced()->getChilds($position) as $_child) {
271
                    if ($view) {
272
                        // if child view is same as given view or the child view is a template of given view
273
                        if ($_child->getView() && ($view == $_child->getView() || $_child->getView()->isTemplateOf($view))) {
274
275
                            // if child is a substitute in view
276
                            if ($substitute = $_child->getSubstituteForView($view)) {
277
                                // if i'm not the parent of the substitute or i does not have the same position, child is not valid
278
                                if ($substitute->getParent() != $this || $substitute->getPosition() != $position) {
279
                                    $_child = null;
280
                                }
281
                            }
282
                            $children[$position] = $_child;
283
                        }
284
                    } else {
285
                        $children[$position] = $_child;
286
                    }
287
                }
288
            }
289
        }