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