Conditions | 4 |
Paths | 6 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
10 | 2 | public function extract(string $filepath, string $nodeName): \Traversable |
|
11 | { |
||
12 | 2 | $xml = new \XMLReader(); |
|
13 | |||
14 | 2 | if (false !== strpos($filepath, '.gz')) { |
|
15 | 1 | $xml->open('compress.zlib://'.$filepath); |
|
16 | } else { |
||
17 | 1 | $xml->open($filepath); |
|
18 | } |
||
19 | |||
20 | 2 | $itemCount = 0; |
|
21 | 2 | while ($xml->read()) { |
|
22 | 2 | if ($nodeName != $xml->name) { |
|
23 | 2 | continue; |
|
24 | } |
||
25 | |||
26 | 2 | ++$itemCount; |
|
27 | 2 | $element = new \SimpleXMLElement($xml->readOuterXml()); |
|
28 | 2 | $data = json_decode(json_encode($element), true); |
|
29 | |||
30 | 2 | yield $itemCount => $data; |
|
31 | 2 | $xml->next(); |
|
32 | } |
||
35 |