@@ -25,8 +25,12 @@ discard block |
||
| 25 | 25 | public function matches($element) { |
| 26 | 26 | foreach ($this->pseudo as $i => $tokens) { |
| 27 | 27 | $parts = $this->getFuncParts($i, $tokens); |
| 28 | - if ($parts['name'] === null) $parts['name'] = 'data'; |
|
| 29 | - if (!isset($this->functions[$parts['name']])) continue; |
|
| 28 | + if ($parts['name'] === null) { |
|
| 29 | + $parts['name'] = 'data'; |
|
| 30 | + } |
|
| 31 | + if (!isset($this->functions[$parts['name']])) { |
|
| 32 | + continue; |
|
| 33 | + } |
|
| 30 | 34 | if ($this->match($parts, $this->functions[$parts['name']], $element) === false) { |
| 31 | 35 | return false; |
| 32 | 36 | } |
@@ -38,14 +42,17 @@ discard block |
||
| 38 | 42 | private function match($parts, $function, $element) { |
| 39 | 43 | try { |
| 40 | 44 | $matches = $function->match($parts['name'], $parts['args'], $element); |
| 41 | - if ($matches === false) return false; |
|
| 42 | - } |
|
| 43 | - catch (\Exception $e) { |
|
| 45 | + if ($matches === false) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + } catch (\Exception $e) { |
|
| 44 | 49 | throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e); |
| 45 | 50 | } |
| 46 | 51 | } |
| 47 | 52 | private function getFuncParts($i, $tokens) { |
| 48 | - if (isset($this->funcParts[$i])) return $this->funcParts[$i]; |
|
| 53 | + if (isset($this->funcParts[$i])) { |
|
| 54 | + return $this->funcParts[$i]; |
|
| 55 | + } |
|
| 49 | 56 | $parts = []; |
| 50 | 57 | $canCache = true; |
| 51 | 58 | $parts['name'] = $this->getFuncName($tokens); |
@@ -53,37 +60,47 @@ discard block |
||
| 53 | 60 | //If the args are dynamic, it can't be cached as it may change between calls |
| 54 | 61 | $canCache = false; |
| 55 | 62 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
| 56 | - } |
|
| 57 | - else if (count($tokens) > 1) { |
|
| 63 | + } else if (count($tokens) > 1) { |
|
| 58 | 64 | $tokens->rewind(); |
| 59 | 65 | $tokens->next(); |
| 60 | 66 | $this->skipWhitespace($tokens); |
| 61 | 67 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
| 68 | + } else { |
|
| 69 | + $parts['args'] = [['']]; |
|
| 70 | + } |
|
| 71 | + if ($canCache) { |
|
| 72 | + $this->funcParts[$i] = $parts; |
|
| 62 | 73 | } |
| 63 | - else $parts['args'] = [['']]; |
|
| 64 | - if ($canCache) $this->funcParts[$i] = $parts; |
|
| 65 | 74 | return $parts; |
| 66 | 75 | } |
| 67 | 76 | |
| 68 | 77 | private function skipWhitespace($tokens) { |
| 69 | - while ($tokens->current()['type'] === 'WHITESPACE' || $tokens->current()['type'] == 'NEWLINE') $tokens->next(); |
|
| 78 | + while ($tokens->current()['type'] === 'WHITESPACE' || $tokens->current()['type'] == 'NEWLINE') { |
|
| 79 | + $tokens->next(); |
|
| 80 | + } |
|
| 70 | 81 | } |
| 71 | 82 | |
| 72 | 83 | private function getFuncName($tokens) { |
| 73 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
| 84 | + if ($tokens->type() === Tokenizer::NAME) { |
|
| 85 | + return $tokens->read(); |
|
| 86 | + } |
|
| 74 | 87 | return null; |
| 75 | 88 | } |
| 76 | 89 | |
| 77 | 90 | public function hasFunction($name) { |
| 78 | 91 | foreach ($this->pseudo as $tokens) { |
| 79 | - if ($name === $this->getFuncName($tokens)) return true; |
|
| 92 | + if ($name === $this->getFuncName($tokens)) { |
|
| 93 | + return true; |
|
| 94 | + } |
|
| 80 | 95 | } |
| 81 | 96 | } |
| 82 | 97 | |
| 83 | 98 | public function getFuncArgs($name) { |
| 84 | 99 | foreach ($this->pseudo as $i => $tokens) { |
| 85 | 100 | $parts = $this->getFuncParts($i, $tokens); |
| 86 | - if ($name === $parts['name']) return $parts['args']; |
|
| 101 | + if ($name === $parts['name']) { |
|
| 102 | + return $parts['args']; |
|
| 103 | + } |
|
| 87 | 104 | } |
| 88 | 105 | } |
| 89 | 106 | } |