Code Duplication    Length = 20-23 lines in 2 locations

lib/Config/Builder.php 2 locations

@@ 251-273 (lines=23) @@
248
        }
249
    }
250
251
    public function mergeStructure(MergedStructure $base, \SimpleXMLElement $new)
252
    {
253
        $base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
254
        foreach ($new as $item) {
255
            if ($item instanceof \SimpleXMLElement) {
256
                $xpath = sprintf('/*/s:section[@identifier="%s"]', $item['identifier']);
257
                $sectionExists = $base->xpath($xpath);
258
259
                if (!empty($sectionExists) && $sectionExists[0] instanceof \SimpleXMLElement) {
260
                    $section = $sectionExists[0];
261
                } else {
262
                    $section = $base->addChild('section');
263
                }
264
265
                foreach ($item->attributes() as $name => $value) {
266
                    $section[$name] = (string)$value;
267
                }
268
                if ($item->group) {
269
                    $this->mergeGroup($section, $item->group);
270
                }
271
            }
272
        }
273
    }
274
275
    protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups)
276
    {
@@ 275-294 (lines=20) @@
272
        }
273
    }
274
275
    protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups)
276
    {
277
        $section->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
278
        foreach ($newGroups as $newGroup) {
279
            if ($newGroup instanceof \SimpleXMLElement) {
280
                $xpath = sprintf('./s:group[@identifier="%s"]', $newGroup['identifier']);
281
                $groupExists = $section->xpath($xpath);
282
283
                if (!empty($groupExists) && $groupExists[0] instanceof \SimpleXMLElement) {
284
                    $group = $groupExists[0];
285
                } else {
286
                    $group = $section->addChild('group');
287
                }
288
                foreach ($newGroup->attributes() as $name => $value) {
289
                    $group[$name] = (string)$value;
290
                }
291
                $this->mergeElements($group, $newGroup->element);
292
            }
293
        }
294
    }
295
296
    protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements)
297
    {