@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function &getLine() { |
| 43 | - $line = &$this->line; |
|
| 43 | + $line = &$this->line; |
|
| 44 | 44 | return $line; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $this->properties[$name] = $property; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
| 72 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 73 | - } |
|
| 71 | + public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
| 72 | + if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | public function registerPseudo($name, Pseudo $pseudo) { |
| 76 | 76 | $this->pseudo[$name] = $pseudo; |
@@ -69,7 +69,9 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
| 72 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 72 | + if (isset($this->properties['content'])) { |
|
| 73 | + $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 74 | + } |
|
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | public function registerPseudo($name, Pseudo $pseudo) { |
@@ -77,12 +79,16 @@ discard block |
||
| 77 | 79 | } |
| 78 | 80 | |
| 79 | 81 | public function loadProperties(Hook\PropertyHook $hook) { |
| 80 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 82 | + foreach ($this->properties as $name => $property) { |
|
| 83 | + $hook->registerProperty($name, $property); |
|
| 84 | + } |
|
| 81 | 85 | } |
| 82 | 86 | |
| 83 | 87 | public function createPseudoMatcher($pseudo) { |
| 84 | 88 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
| 85 | - foreach ($this->pseudo as $name => $pseudoFunction) $pseudoMatcher->registerFunction($name, clone $pseudoFunction); |
|
| 89 | + foreach ($this->pseudo as $name => $pseudoFunction) { |
|
| 90 | + $pseudoMatcher->registerFunction($name, clone $pseudoFunction); |
|
| 91 | + } |
|
| 86 | 92 | return $pseudoMatcher; |
| 87 | 93 | } |
| 88 | 94 | |
@@ -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']])) return true; |
|
| 28 | + if ($parts['name'] === null) { |
|
| 29 | + $parts['name'] = 'data'; |
|
| 30 | + } |
|
| 31 | + if (!isset($this->functions[$parts['name']])) { |
|
| 32 | + return true; |
|
| 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,32 +60,40 @@ 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 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
| 67 | + } else { |
|
| 68 | + $parts['args'] = [['']]; |
|
| 69 | + } |
|
| 70 | + if ($canCache) { |
|
| 71 | + $this->funcParts[$i] = $parts; |
|
| 61 | 72 | } |
| 62 | - else $parts['args'] = [['']]; |
|
| 63 | - if ($canCache) $this->funcParts[$i] = $parts; |
|
| 64 | 73 | return $parts; |
| 65 | 74 | } |
| 66 | 75 | |
| 67 | 76 | private function getFuncName($tokens) { |
| 68 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
| 77 | + if ($tokens->type() === Tokenizer::NAME) { |
|
| 78 | + return $tokens->read(); |
|
| 79 | + } |
|
| 69 | 80 | return null; |
| 70 | 81 | } |
| 71 | 82 | |
| 72 | 83 | public function hasFunction($name) { |
| 73 | 84 | foreach ($this->pseudo as $tokens) { |
| 74 | - if ($name === $this->getFuncName($tokens)) return true; |
|
| 85 | + if ($name === $this->getFuncName($tokens)) { |
|
| 86 | + return true; |
|
| 87 | + } |
|
| 75 | 88 | } |
| 76 | 89 | } |
| 77 | 90 | |
| 78 | 91 | public function getFuncArgs($name) { |
| 79 | 92 | foreach ($this->pseudo as $i => $tokens) { |
| 80 | 93 | $parts = $this->getFuncParts($i, $tokens); |
| 81 | - if ($name === $parts['name']) return $parts['args']; |
|
| 94 | + if ($name === $parts['name']) { |
|
| 95 | + return $parts['args']; |
|
| 96 | + } |
|
| 82 | 97 | } |
| 83 | 98 | } |
| 84 | 99 | } |
@@ -54,7 +54,9 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function parseTokens($tokens, $data = null) { |
| 57 | - if (count($tokens) === 0) return [$data]; |
|
| 57 | + if (count($tokens) === 0) { |
|
| 58 | + return [$data]; |
|
| 59 | + } |
|
| 58 | 60 | |
| 59 | 61 | $this->result = new ValueResult(); |
| 60 | 62 | $this->data = new ValueData($data ? $data : $this->baseData); |
@@ -64,7 +66,9 @@ discard block |
||
| 64 | 66 | |
| 65 | 67 | |
| 66 | 68 | foreach ($tokens as $name => $token) { |
| 67 | - if ($token['type'] == 'WHITESPACE' || $token['type'] == 'NEWLINE') continue; |
|
| 69 | + if ($token['type'] == 'WHITESPACE' || $token['type'] == 'NEWLINE') { |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 68 | 72 | $this->{$this->tokenFuncs[$token['type']]}($token); |
| 69 | 73 | } |
| 70 | 74 | |
@@ -91,8 +95,7 @@ discard block |
||
| 91 | 95 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
| 92 | 96 | if ($lastResult) { |
| 93 | 97 | $this->last->makeTraversing(); |
| 94 | - } |
|
| 95 | - else if ($this->last->isEmpty()) { |
|
| 98 | + } else if ($this->last->isEmpty()) { |
|
| 96 | 99 | $this->processString(['value' => '.']); |
| 97 | 100 | $this->result->setMode(Tokenizer::CONCAT); |
| 98 | 101 | } |
@@ -107,11 +110,12 @@ discard block |
||
| 107 | 110 | private function processSquareBracket($token) { |
| 108 | 111 | if ($this->hasFunction($this->last->read())) { |
| 109 | 112 | $this->callTransphpormFunctions($token); |
| 110 | - } |
|
| 111 | - else { |
|
| 113 | + } else { |
|
| 112 | 114 | $this->last->traverse(); |
| 113 | 115 | $this->last->set($this->getNewParser()->parseTokens($token['value'], null)[0]); |
| 114 | - if (!is_bool($this->last->read())) $this->last->makeTraversing(); |
|
| 116 | + if (!is_bool($this->last->read())) { |
|
| 117 | + $this->last->makeTraversing(); |
|
| 118 | + } |
|
| 115 | 119 | } |
| 116 | 120 | } |
| 117 | 121 | |
@@ -134,8 +138,7 @@ discard block |
||
| 134 | 138 | if ($this->hasFunction($this->last->read()) |
| 135 | 139 | && !$this->data->methodExists($this->last->read())) { |
| 136 | 140 | $this->callTransphpormFunctions($token); |
| 137 | - } |
|
| 138 | - else { |
|
| 141 | + } else { |
|
| 139 | 142 | $this->last->processNested($this->getNewParser(), $token); |
| 140 | 143 | } |
| 141 | 144 | } |
@@ -152,8 +155,9 @@ discard block |
||
| 152 | 155 | $parser = new Value($this->data->getData()); |
| 153 | 156 | $parsedArr = $parser->parse($val); |
| 154 | 157 | $parsedVal = isset($parsedArr[0]) ? $parsedArr[0] : null; |
| 158 | + } else { |
|
| 159 | + $parsedVal = null; |
|
| 155 | 160 | } |
| 156 | - else $parsedVal = null; |
|
| 157 | 161 | |
| 158 | 162 | $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult); |
| 159 | 163 | |
@@ -7,7 +7,9 @@ |
||
| 7 | 7 | namespace Transphporm\Pseudo; |
| 8 | 8 | class Attribute implements \Transphporm\Pseudo { |
| 9 | 9 | public function match($name, $args, \DomElement $element) { |
| 10 | - if ($name === null) return true; |
|
| 10 | + if ($name === null) { |
|
| 11 | + return true; |
|
| 12 | + } |
|
| 11 | 13 | return $args[0]; |
| 12 | 14 | } |
| 13 | 15 | } |