| Conditions | 5 |
| Paths | 3 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 53 | protected function getTextFromArticle(DOMNodeList $articles): string |
||
| 54 | { |
||
| 55 | $text = ''; |
||
| 56 | |||
| 57 | for ($i = 0; $i < $articles->length; $i++) |
||
| 58 | { |
||
| 59 | // Check element if there is a childNodes |
||
| 60 | if ($articles->item($i)->childNodes === null) |
||
| 61 | { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | $dit = new RecursiveIteratorIterator( |
||
| 66 | new RecursiveDOMIterator($articles->item($i)), |
||
| 67 | RecursiveIteratorIterator::SELF_FIRST |
||
| 68 | ); |
||
| 69 | foreach ($dit as $node) |
||
| 70 | { |
||
| 71 | if ($node->nodeName === 'p') |
||
| 72 | { |
||
| 73 | $text .= $node->textContent; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $text; |
||
| 79 | } |
||
| 80 | } |
If you suppress an error, we recommend checking for the error condition explicitly: