Code Duplication    Length = 20-23 lines in 2 locations

lib/Config/Builder.php 2 locations

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