| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5.009 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | 52 | public static function toXPath($selector) |
|
| 22 | { |
||
| 23 | 52 | if (isset(self::$compiled[$selector])) { |
|
| 24 | 42 | return self::$compiled[$selector]; |
|
| 25 | } |
||
| 26 | |||
| 27 | // Select DOMText |
||
| 28 | 24 | if ($selector === 'text') { |
|
| 29 | 3 | return '//text()'; |
|
| 30 | } |
||
| 31 | |||
| 32 | // Select DOMComment |
||
| 33 | 21 | if ($selector === 'comment') { |
|
| 34 | 2 | return '//comment()'; |
|
| 35 | } |
||
| 36 | |||
| 37 | 19 | 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 | 1 | } |
|
| 40 | |||
| 41 | 19 | $converter = new CssSelectorConverter(true); |
|
| 42 | |||
| 43 | 19 | $xPathQuery = $converter->toXPath($selector); |
|
| 44 | 19 | self::$compiled[$selector] = $xPathQuery; |
|
| 45 | |||
| 46 | 19 | return $xPathQuery; |
|
| 47 | } |
||
| 48 | } |
||
| 49 |