| Conditions | 3 |
| Paths | 3 |
| Total Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 3.0017 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 17 | public static function htmlXPath(\DOMDocument &$DOMDocument, $html, $xpathQuery) |
|
| 13 | { |
||
| 14 | 17 | $html = self::normalizeHTML($html); |
|
|
|
|||
| 15 | |||
| 16 | 17 | libxml_use_internal_errors(true); |
|
| 17 | |||
| 18 | 17 | $DOMDocument->loadHTML( |
|
| 19 | 17 | mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), |
|
| 20 | 17 | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD |
|
| 21 | 17 | ); |
|
| 22 | |||
| 23 | 17 | $xmlErrors = libxml_get_errors(); |
|
| 24 | |||
| 25 | /** @var \LibXMLError $error */ |
||
| 26 | 17 | foreach ($xmlErrors as $error) |
|
| 27 | { |
||
| 28 | // Ignore errors about invalid tags |
||
| 29 | // http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors |
||
| 30 | 1 | if ($error->code === 801) |
|
| 31 | 1 | { |
|
| 32 | continue; |
||
| 33 | } |
||
| 34 | |||
| 35 | 1 | @trigger_error($error->message, E_USER_WARNING); |
|
| 36 | 17 | } |
|
| 37 | |||
| 38 | 17 | libxml_clear_errors(); |
|
| 39 | |||
| 40 | 17 | $xpath = new \DOMXPath($DOMDocument); |
|
| 41 | |||
| 42 | 17 | return $xpath->query($xpathQuery); |
|
| 43 | } |
||
| 44 | |||
| 55 |