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