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