Code Duplication    Length = 20-23 lines in 2 locations

lib/Config/Builder.php 2 locations

@@ 162-184 (lines=23) @@
159
        }
160
    }
161
162
    public function mergeStructure(\SimpleXMLElement $base, \SimpleXMLElement $new)
163
    {
164
        $base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
165
        foreach ($new as $item) {
166
            if ($item instanceof \SimpleXMLElement) {
167
                $xpath = sprintf('/*/s:section[@id="%s"]', $item['id']);
168
                $sectionExists = $base->xpath($xpath);
169
170
                if (!empty($sectionExists) && $sectionExists[0] instanceof \SimpleXMLElement) {
171
                    $section = $sectionExists[0];
172
                } else {
173
                    $section = $base->addChild('section');
174
                }
175
176
                foreach ($item->attributes() as $name => $value) {
177
                    $section[$name] = $value;
178
                }
179
                if ($item->group) {
180
                    $this->mergeGroup($section, $item->group);
181
                }
182
            }
183
        }
184
    }
185
186
    protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups)
187
    {
@@ 186-205 (lines=20) @@
183
        }
184
    }
185
186
    protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups)
187
    {
188
        $section->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
189
        foreach ($newGroups as $newGroup) {
190
            if ($newGroup instanceof \SimpleXMLElement) {
191
                $xpath = sprintf('./s:group[@id="%s"]', $newGroup['id']);
192
                $groupExists = $section->xpath($xpath);
193
194
                if (!empty($groupExists) && $groupExists[0] instanceof \SimpleXMLElement) {
195
                    $group = $groupExists[0];
196
                } else {
197
                    $group = $section->addChild('group');
198
                }
199
                foreach ($newGroup->attributes() as $name => $value) {
200
                    $group[$name] = $value;
201
                }
202
                $this->mergeElements($group, $newGroup->element);
203
            }
204
        }
205
    }
206
207
    protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements)
208
    {