| Conditions | 6 |
| Paths | 6 |
| Total Lines | 31 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 6.0106 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | 81 | public static function toXPath(string $selector) |
|
| 26 | { |
||
| 27 | 81 | if (isset(self::$compiled[$selector])) { |
|
| 28 | 61 | return self::$compiled[$selector]; |
|
| 29 | } |
||
| 30 | |||
| 31 | // Select DOMText |
||
| 32 | 38 | if ($selector === 'text') { |
|
| 33 | 3 | return '//text()'; |
|
| 34 | } |
||
| 35 | |||
| 36 | // Select DOMComment |
||
| 37 | 35 | if ($selector === 'comment') { |
|
| 38 | 2 | return '//comment()'; |
|
| 39 | } |
||
| 40 | |||
| 41 | 33 | if (\strpos($selector, '//') === 0) { |
|
| 42 | 1 | return $selector; |
|
| 43 | } |
||
| 44 | |||
| 45 | 33 | if (!\class_exists(CssSelectorConverter::class)) { |
|
| 46 | throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).'); |
||
| 47 | } |
||
| 48 | |||
| 49 | 33 | $converter = new CssSelectorConverter(true); |
|
| 50 | |||
| 51 | 33 | $xPathQuery = $converter->toXPath($selector); |
|
| 52 | 33 | self::$compiled[$selector] = $xPathQuery; |
|
| 53 | |||
| 54 | 33 | return $xPathQuery; |
|
| 55 | } |
||
| 56 | } |
||
| 57 |