@@ -20,12 +20,12 @@ discard block |
||
| 20 | 20 | $this->functionSet = $functionSet; |
| 21 | 21 | |
| 22 | 22 | $this->translators = [ |
| 23 | - ' ' => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
| 24 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 25 | - '>' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 26 | - '#' => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
| 27 | - '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
| 28 | - '[' => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . $string . '\', ., "' . $hash . '")' . ']'; }, |
|
| 23 | + ' ' => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
| 24 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 25 | + '>' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 26 | + '#' => function($string) { return '[@id=\''.$string.'\']'; }, |
|
| 27 | + '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
| 28 | + '[' => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.$string.'\', ., "'.$hash.'")'.']'; }, |
|
| 29 | 29 | ']' => function() { return ''; } |
| 30 | 30 | ]; |
| 31 | 31 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | public function getXpath($css) { |
| 88 | - $this->css = str_replace([' >', '> '],['>', '>'], trim($css)); |
|
| 88 | + $this->css = str_replace([' >', '> '], ['>', '>'], trim($css)); |
|
| 89 | 89 | $css = explode(':', $this->css)[0]; |
| 90 | 90 | $selectors = $this->split($css); |
| 91 | 91 | $xpath = '/'; |
@@ -63,8 +63,11 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | private static function compare($comparator, $a, $b) { |
| 66 | - if ($comparator == '=') return $a == $b; |
|
| 67 | - else if ($comparator == '!=') return $a != $b; |
|
| 66 | + if ($comparator == '=') { |
|
| 67 | + return $a == $b; |
|
| 68 | + } else if ($comparator == '!=') { |
|
| 69 | + return $a != $b; |
|
| 70 | + } |
|
| 68 | 71 | } |
| 69 | 72 | |
| 70 | 73 | //split the css into indivudal functions |
@@ -78,8 +81,9 @@ discard block |
||
| 78 | 81 | $selector = $this->createSelector(); |
| 79 | 82 | $selector->type = $css[$i]; |
| 80 | 83 | $selectors[] = $selector; |
| 84 | + } else { |
|
| 85 | + $selector->string .= $css[$i]; |
|
| 81 | 86 | } |
| 82 | - else $selector->string .= $css[$i]; |
|
| 83 | 87 | } |
| 84 | 88 | return $selectors; |
| 85 | 89 | } |
@@ -90,7 +94,9 @@ discard block |
||
| 90 | 94 | $selectors = $this->split($css); |
| 91 | 95 | $xpath = '/'; |
| 92 | 96 | foreach ($selectors as $selector) { |
| 93 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
| 97 | + if (isset($this->translators[$selector->type])) { |
|
| 98 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
| 99 | + } |
|
| 94 | 100 | } |
| 95 | 101 | |
| 96 | 102 | $xpath = str_replace('/[', '/*[', $xpath); |