| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5.0113 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 54 | public static function toXPath($selector) |
|
| 17 | { |
||
| 18 | 54 | if (isset(self::$compiled[$selector])) { |
|
| 19 | 44 | return self::$compiled[$selector]; |
|
| 20 | } |
||
| 21 | |||
| 22 | // Select DOMText |
||
| 23 | 24 | if ($selector === 'text') { |
|
| 24 | 3 | return '//text()'; |
|
| 25 | } |
||
| 26 | |||
| 27 | // Select DOMComment |
||
| 28 | 21 | if ($selector === 'comment') { |
|
| 29 | 2 | return '//comment()'; |
|
| 30 | } |
||
| 31 | |||
| 32 | 19 | if (!class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) { |
|
| 33 | throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).'); |
||
| 34 | } |
||
| 35 | |||
| 36 | 19 | $converter = new CssSelectorConverter(true); |
|
| 37 | |||
| 38 | 19 | $xPathQuery = $converter->toXPath($selector); |
|
| 39 | 19 | self::$compiled[$selector] = $xPathQuery; |
|
| 40 | |||
| 41 | 19 | return $xPathQuery; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |