| 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 |
||
| 21 | 76 | public static function toXPath($selector) |
|
| 22 | { |
||
| 23 | 76 | if (isset(self::$compiled[$selector])) { |
|
| 24 | 57 | return self::$compiled[$selector]; |
|
| 25 | } |
||
| 26 | |||
| 27 | // Select DOMText |
||
| 28 | 36 | if ($selector === 'text') { |
|
| 29 | 3 | return '//text()'; |
|
| 30 | } |
||
| 31 | |||
| 32 | // Select DOMComment |
||
| 33 | 33 | if ($selector === 'comment') { |
|
| 34 | 2 | return '//comment()'; |
|
| 35 | } |
||
| 36 | |||
| 37 | 31 | if (!class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) { |
|
| 38 | throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).'); |
||
| 39 | } |
||
| 40 | |||
| 41 | 31 | $converter = new CssSelectorConverter(true); |
|
| 42 | |||
| 43 | 31 | $xPathQuery = $converter->toXPath($selector); |
|
| 44 | 31 | self::$compiled[$selector] = $xPathQuery; |
|
| 45 | |||
| 46 | 31 | return $xPathQuery; |
|
| 47 | } |
||
| 48 | } |
||
| 49 |