@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | private $rules; |
| 11 | 11 | private $configLine; |
| 12 | 12 | private $file; |
| 13 | - private $filePath; |
|
| 13 | + private $filePath; |
|
| 14 | 14 | private $line; |
| 15 | 15 | private $valueParser; |
| 16 | 16 | private $pseudoMatcher; |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | private $functionSet; |
| 19 | 19 | |
| 20 | 20 | public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher, |
| 21 | - \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
| 21 | + \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
| 22 | 22 | $this->rules = $rules; |
| 23 | 23 | $this->configLine = &$configLine; |
| 24 | 24 | $this->file = $file; |
| 25 | - $this->filePath = $filePath; |
|
| 25 | + $this->filePath = $filePath; |
|
| 26 | 26 | $this->line = $line; |
| 27 | 27 | $this->valueParser = $valueParser; |
| 28 | 28 | $this->pseudoMatcher = $pseudoMatcher; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function run(\DomElement $element) { |
| 33 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR); |
|
| 33 | + if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR); |
|
| 34 | 34 | $this->functionSet->setElement($element); |
| 35 | 35 | $this->configLine = $this->line; |
| 36 | 36 | try { |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function run(\DomElement $element) { |
| 33 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR); |
|
| 33 | + if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)).DIRECTORY_SEPARATOR); |
|
| 34 | 34 | $this->functionSet->setElement($element); |
| 35 | 35 | $this->configLine = $this->line; |
| 36 | 36 | try { |
@@ -30,15 +30,18 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function run(\DomElement $element) { |
| 33 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR); |
|
| 33 | + if ($this->file !== null) { |
|
| 34 | + $this->filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR); |
|
| 35 | + } |
|
| 34 | 36 | $this->functionSet->setElement($element); |
| 35 | 37 | $this->configLine = $this->line; |
| 36 | 38 | try { |
| 37 | 39 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
| 38 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
| 40 | + if (!$this->pseudoMatcher->matches($element)) { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 39 | 43 | $this->callProperties($element); |
| 40 | - } |
|
| 41 | - catch (\Transphporm\RunException $e) { |
|
| 44 | + } catch (\Transphporm\RunException $e) { |
|
| 42 | 45 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
| 43 | 46 | } |
| 44 | 47 | } |
@@ -49,7 +52,9 @@ discard block |
||
| 49 | 52 | private function callProperties($element) { |
| 50 | 53 | foreach ($this->rules as $name => $value) { |
| 51 | 54 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
| 52 | - if ($result === false) break; |
|
| 55 | + if ($result === false) { |
|
| 56 | + break; |
|
| 57 | + } |
|
| 53 | 58 | } |
| 54 | 59 | } |
| 55 | 60 | private function getArgs($value) { |
@@ -64,9 +69,10 @@ discard block |
||
| 64 | 69 | if (isset($this->properties[$name])) { |
| 65 | 70 | try { |
| 66 | 71 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
| 67 | - } |
|
| 68 | - catch (\Exception $e) { |
|
| 69 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
| 72 | + } catch (\Exception $e) { |
|
| 73 | + if ($e instanceof \Transphporm\RunException) { |
|
| 74 | + throw $e; |
|
| 75 | + } |
|
| 70 | 76 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
| 71 | 77 | } |
| 72 | 78 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $this->translators = [ |
| 22 | 22 | Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
| 23 | - Tokenizer::MULTIPLY => function () { return '*'; }, |
|
| 23 | + Tokenizer::MULTIPLY => function () { return '*'; }, |
|
| 24 | 24 | '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
| 25 | 25 | Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
| 26 | 26 | Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | $functionSet->setElement($element[0]); |
| 45 | 45 | |
| 46 | 46 | $attributes = array(); |
| 47 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 48 | - $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
| 49 | - } |
|
| 47 | + foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 48 | + $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
| 51 | + $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
| 52 | 52 | $return = $parser->parseTokens($attr, $attributes); |
| 53 | 53 | |
| 54 | 54 | return $return[0] === '' ? false : $return[0]; |
@@ -19,13 +19,13 @@ discard block |
||
| 19 | 19 | $this->functionSet = $functionSet; |
| 20 | 20 | |
| 21 | 21 | $this->translators = [ |
| 22 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
| 23 | - Tokenizer::MULTIPLY => function () { return '*'; }, |
|
| 24 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 25 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 26 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
| 27 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
| 28 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $hash . '")' . ']'; } |
|
| 22 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
| 23 | + Tokenizer::MULTIPLY => function() { return '*'; }, |
|
| 24 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 25 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 26 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
| 27 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
| 28 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$hash.'")'.']'; } |
|
| 29 | 29 | ]; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $functionSet->setElement($element[0]); |
| 45 | 45 | |
| 46 | 46 | $attributes = array(); |
| 47 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 47 | + foreach ($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 48 | 48 | $attributes[$attribute_name] = $attribute_node->nodeValue; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | private function removeSpacesFromDirectDecend($css) { |
| 92 | 92 | $tokens = []; |
| 93 | 93 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
| 94 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
| 94 | + foreach ($token->trim() as $t) $tokens[] = $t; |
|
| 95 | 95 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
| 96 | 96 | } |
| 97 | 97 | return new Tokens(array_slice($tokens, 0, -1)); |