Conditions | 3 |
Paths | 3 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 3.0017 |
Changes | 0 |
1 | <?php |
||
12 | 11 | public static function htmlXPath(\DOMDocument &$DOMDocument, $html, $xpathQuery) |
|
13 | { |
||
14 | 11 | $html = self::normalizeHTML($html); |
|
|
|||
15 | |||
16 | 11 | libxml_use_internal_errors(true); |
|
17 | |||
18 | 11 | $DOMDocument->loadHTML( |
|
19 | 11 | mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), |
|
20 | 11 | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD |
|
21 | 11 | ); |
|
22 | |||
23 | 11 | $xmlErrors = libxml_get_errors(); |
|
24 | |||
25 | /** @var \LibXMLError $error */ |
||
26 | 11 | 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 | 11 | } |
|
37 | |||
38 | 11 | libxml_clear_errors(); |
|
39 | |||
40 | 11 | $xpath = new \DOMXPath($DOMDocument); |
|
41 | |||
42 | 11 | return $xpath->query($xpathQuery); |
|
43 | } |
||
44 | |||
62 |