| Conditions | 2 |
| Paths | 2 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 2.0008 |
| Changes | 0 | ||
| 1 | <?php |
||
| 58 | 1 | public static function getNodeHtml(Crawler $node) |
|
| 59 | { |
||
| 60 | 1 | $domNode = $node->getNode(0); |
|
| 61 | |||
| 62 | 1 | if (null === $domNode) { |
|
| 63 | return ''; |
||
| 64 | } |
||
| 65 | |||
| 66 | 1 | $html = $domNode->ownerDocument->saveHtml($domNode); |
|
| 67 | |||
| 68 | // remove line breaks |
||
| 69 | 1 | $html = str_replace(array("\n", "\r"), '', $html); |
|
| 70 | |||
| 71 | // remove surrounding tag |
||
| 72 | 1 | $regExp = '/'; |
|
| 73 | 1 | $regExp .= '<(?<tag>.*)>'; |
|
| 74 | 1 | $regExp .= '(?<html>.*)$'; |
|
| 75 | 1 | $regExp .= '/Ums'; // Ungreedy, multiline, dotall |
|
| 76 | |||
| 77 | 1 | $html = preg_replace_callback( |
|
| 78 | 1 | $regExp, |
|
| 79 | 1 | function ($matches) { |
|
| 80 | 1 | return '<' . $matches['tag'] . '>' . $matches['html']; |
|
| 81 | 1 | }, |
|
| 82 | $html |
||
| 83 | 1 | ); |
|
| 84 | |||
| 85 | 1 | return $html; |
|
| 86 | } |
||
| 87 | } |
||
| 88 |