@@ -28,6 +28,9 @@ discard block |
||
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | + /** |
|
32 | + * @param \DOMElement $element |
|
33 | + */ |
|
31 | 34 | private function shouldRun($element) { |
32 | 35 | do { |
33 | 36 | if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
@@ -40,6 +43,10 @@ discard block |
||
40 | 43 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
41 | 44 | } |
42 | 45 | |
46 | + /** |
|
47 | + * @param \DOMElement $element |
|
48 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
49 | + */ |
|
43 | 50 | private function processPseudo($value, $element, $pseudoMatcher) { |
44 | 51 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
45 | 52 | foreach ($pseudoContent as $pseudo) { |
@@ -96,6 +103,9 @@ discard block |
||
96 | 103 | } |
97 | 104 | } |
98 | 105 | |
106 | + /** |
|
107 | + * @param \DOMElement $element |
|
108 | + */ |
|
99 | 109 | private function replaceContent($element, $content) { |
100 | 110 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
101 | 111 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
@@ -104,12 +114,18 @@ discard block |
||
104 | 114 | $element->setAttribute('transphporm', 'remove'); |
105 | 115 | } |
106 | 116 | |
117 | + /** |
|
118 | + * @param \DOMElement $element |
|
119 | + */ |
|
107 | 120 | private function appendContent($element, $content) { |
108 | 121 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
109 | 122 | $element->appendChild($node); |
110 | 123 | } |
111 | 124 | } |
112 | 125 | |
126 | + /** |
|
127 | + * @param \DOMElement $element |
|
128 | + */ |
|
113 | 129 | private function removeAllChildren($element) { |
114 | 130 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
115 | 131 | } |
@@ -16,21 +16,28 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
19 | - if (!$this->shouldRun($element)) return false; |
|
19 | + if (!$this->shouldRun($element)) { |
|
20 | + return false; |
|
21 | + } |
|
20 | 22 | $values = $this->formatter->format($values, $rules); |
21 | 23 | |
22 | 24 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
23 | 25 | //Remove the current contents |
24 | 26 | $this->removeAllChildren($element); |
25 | 27 | //Now make a text node |
26 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
27 | - else $this->appendContent($element, $values); |
|
28 | + if ($this->getContentMode($rules) === 'replace') { |
|
29 | + $this->replaceContent($element, $values); |
|
30 | + } else { |
|
31 | + $this->appendContent($element, $values); |
|
32 | + } |
|
28 | 33 | } |
29 | 34 | } |
30 | 35 | |
31 | 36 | private function shouldRun($element) { |
32 | 37 | do { |
33 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
38 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
39 | + return false; |
|
40 | + } |
|
34 | 41 | } |
35 | 42 | while (($element = $element->parentNode) instanceof \DomElement); |
36 | 43 | return true; |
@@ -54,16 +61,18 @@ discard block |
||
54 | 61 | private function getNode($node, $document) { |
55 | 62 | foreach ($node as $n) { |
56 | 63 | if (is_array($n)) { |
57 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
58 | - } |
|
59 | - else { |
|
64 | + foreach ($this->getNode($n, $document) as $new) { |
|
65 | + yield $new; |
|
66 | + } |
|
67 | + } else { |
|
60 | 68 | if ($n instanceof \DomElement) { |
61 | 69 | $new = $document->importNode($n, true); |
62 | 70 | //Removing this might cause problems with caching... |
63 | 71 | //$new->setAttribute('transphporm', 'added'); |
64 | - } |
|
65 | - else { |
|
66 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
72 | + } else { |
|
73 | + if ($n instanceof \DomText) { |
|
74 | + $n = $n->nodeValue; |
|
75 | + } |
|
67 | 76 | $new = $document->createElement('text'); |
68 | 77 | |
69 | 78 | $new->appendChild($document->createTextNode($n)); |
@@ -111,6 +120,8 @@ discard block |
||
111 | 120 | } |
112 | 121 | |
113 | 122 | private function removeAllChildren($element) { |
114 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
123 | + while ($element->hasChildNodes()) { |
|
124 | + $element->removeChild($element->firstChild); |
|
125 | + } |
|
115 | 126 | } |
116 | 127 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | |
85 | 85 | private function import($args, $indexStart) { |
86 | 86 | $fileName = $args[0]; |
87 | - $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
87 | + $sheet = new Sheet(file_get_contents($this->baseDir.$fileName), dirname(realpath($this->baseDir.$fileName)).DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
88 | 88 | return $sheet->parse($indexStart); |
89 | 89 | } |
90 | 90 |
@@ -13,6 +13,9 @@ discard block |
||
13 | 13 | private $xPath; |
14 | 14 | private $tokenizer; |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $tss |
|
18 | + */ |
|
16 | 19 | public function __construct($tss, $baseDir, CssToXpath $xPath, Value $valueParser) { |
17 | 20 | $this->tss = $this->stripComments($tss, '//', "\n"); |
18 | 21 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -44,6 +47,9 @@ discard block |
||
44 | 47 | return $rules; |
45 | 48 | } |
46 | 49 | |
50 | + /** |
|
51 | + * @param integer $index |
|
52 | + */ |
|
47 | 53 | private function CssToRules($selector, $index, $properties) { |
48 | 54 | $parts = $selector->trim()->splitOnToken(Tokenizer::ARG); |
49 | 55 | $rules = []; |
@@ -67,6 +73,9 @@ discard block |
||
67 | 73 | return $rules; |
68 | 74 | } |
69 | 75 | |
76 | + /** |
|
77 | + * @param integer $indexStart |
|
78 | + */ |
|
70 | 79 | private function processingInstructions($token, $indexStart) { |
71 | 80 | if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
72 | 81 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
@@ -90,6 +99,10 @@ discard block |
||
90 | 99 | return ($a->depth < $b->depth) ? -1 : 1; |
91 | 100 | } |
92 | 101 | |
102 | + /** |
|
103 | + * @param string $open |
|
104 | + * @param string $close |
|
105 | + */ |
|
93 | 106 | private function stripComments($str, $open, $close) { |
94 | 107 | $pos = 0; |
95 | 108 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -102,14 +102,14 @@ |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | private function getProperties($tokens) { |
105 | - $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
105 | + $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
106 | 106 | |
107 | - $return = []; |
|
108 | - foreach ($rules as $rule) { |
|
109 | - $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | - $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | - } |
|
107 | + $return = []; |
|
108 | + foreach ($rules as $rule) { |
|
109 | + $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | + } |
|
112 | 112 | |
113 | - return $return; |
|
114 | - } |
|
113 | + return $return; |
|
114 | + } |
|
115 | 115 | } |
@@ -34,13 +34,17 @@ discard block |
||
34 | 34 | } |
35 | 35 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
36 | 36 | $this->tss->skip(count($selector)); |
37 | - if (!$this->tss->valid() || count($selector) === 0) break; |
|
37 | + if (!$this->tss->valid() || count($selector) === 0) { |
|
38 | + break; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value'])); |
40 | 42 | $rules = $this->writeRule($rules, $newRules); |
41 | 43 | } |
42 | 44 | usort($rules, [$this, 'sortRules']); |
43 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception("No TSS rules parsed"); |
|
45 | + if (empty($rules) && count($this->tss) > 0) { |
|
46 | + throw new \Exception("No TSS rules parsed"); |
|
47 | + } |
|
44 | 48 | return $rules; |
45 | 49 | } |
46 | 50 | |
@@ -68,7 +72,9 @@ discard block |
||
68 | 72 | } |
69 | 73 | |
70 | 74 | private function processingInstructions($token, $indexStart) { |
71 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
75 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
76 | + return false; |
|
77 | + } |
|
72 | 78 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
73 | 79 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
74 | 80 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -85,7 +91,9 @@ discard block |
||
85 | 91 | |
86 | 92 | private function sortRules($a, $b) { |
87 | 93 | //If they have the same depth, compare on index |
88 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
94 | + if ($a->depth === $b->depth) { |
|
95 | + return $a->index < $b->index ? -1 : 1; |
|
96 | + } |
|
89 | 97 | |
90 | 98 | return ($a->depth < $b->depth) ? -1 : 1; |
91 | 99 | } |
@@ -94,7 +102,9 @@ discard block |
||
94 | 102 | $pos = 0; |
95 | 103 | while (($pos = strpos($str, $open, $pos)) !== false) { |
96 | 104 | $end = strpos($str, $close, $pos); |
97 | - if ($end === false) break; |
|
105 | + if ($end === false) { |
|
106 | + break; |
|
107 | + } |
|
98 | 108 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
99 | 109 | } |
100 | 110 |
@@ -49,11 +49,11 @@ |
||
49 | 49 | $functionSet->setElement($element[0]); |
50 | 50 | |
51 | 51 | $attributes = array(); |
52 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
53 | - $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
54 | - } |
|
52 | + foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
53 | + $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
54 | + } |
|
55 | 55 | |
56 | - $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
56 | + $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
57 | 57 | $return = $parser->parseTokens($attr, $attributes); |
58 | 58 | |
59 | 59 | return $return[0] === '' ? false : $return[0]; |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | $this->functionSet = $functionSet; |
19 | 19 | |
20 | 20 | $this->translators = [ |
21 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
22 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
23 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
24 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
25 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
26 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $hash . '")' . ']'; } |
|
21 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
22 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
23 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
24 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
25 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
26 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$hash.'")'.']'; } |
|
27 | 27 | ]; |
28 | 28 | } |
29 | 29 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $functionSet->setElement($element[0]); |
48 | 48 | |
49 | 49 | $attributes = array(); |
50 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
50 | + foreach ($element[0]->attributes as $attribute_name => $attribute_node) { |
|
51 | 51 | $attributes[$attribute_name] = $attribute_node->nodeValue; |
52 | 52 | } |
53 | 53 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $tokens = []; |
79 | 79 | |
80 | 80 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
81 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
81 | + foreach ($token->trim() as $t) $tokens[] = $t; |
|
82 | 82 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
83 | 83 | } |
84 | 84 | $tokens = new Tokens(array_slice($tokens, 0, -1)); |
@@ -69,7 +69,9 @@ discard block |
||
69 | 69 | $selector->type = $token['type']; |
70 | 70 | $selectors[] = $selector; |
71 | 71 | } |
72 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
72 | + if (isset($token['value'])) { |
|
73 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
74 | + } |
|
73 | 75 | } |
74 | 76 | return $selectors; |
75 | 77 | } |
@@ -78,7 +80,9 @@ discard block |
||
78 | 80 | $tokens = []; |
79 | 81 | |
80 | 82 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
81 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
83 | + foreach ($token->trim() as $t) { |
|
84 | + $tokens[] = $t; |
|
85 | + } |
|
82 | 86 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
83 | 87 | } |
84 | 88 | $tokens = new Tokens(array_slice($tokens, 0, -1)); |
@@ -87,7 +91,9 @@ discard block |
||
87 | 91 | $selectors = $this->split($css); |
88 | 92 | $xpath = '/'; |
89 | 93 | foreach ($selectors as $selector) { |
90 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
94 | + if (isset($this->translators[$selector->type])) { |
|
95 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
96 | + } |
|
91 | 97 | } |
92 | 98 | |
93 | 99 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -7,8 +7,12 @@ |
||
7 | 7 | namespace Transphporm\Property; |
8 | 8 | class Display implements \Transphporm\Property { |
9 | 9 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
11 | - else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
12 | - else $element->setAttribute('transphporm', 'show'); |
|
10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
12 | + } else if (strtolower($values[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |
@@ -14,7 +14,9 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function format($value, $rules) { |
17 | - if (!isset($rules['format'])) return $value; |
|
17 | + if (!isset($rules['format'])) { |
|
18 | + return $value; |
|
19 | + } |
|
18 | 20 | $tokens = $rules['format']; |
19 | 21 | |
20 | 22 | $functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read(); |
@@ -39,31 +39,37 @@ |
||
39 | 39 | $parts['name'] = $this->getFuncName($tokens); |
40 | 40 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
41 | 41 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
42 | - } |
|
43 | - else if (count($tokens) > 1) { |
|
42 | + } else if (count($tokens) > 1) { |
|
44 | 43 | $tokens->rewind(); |
45 | 44 | $tokens->next(); |
46 | 45 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
46 | + } else { |
|
47 | + $parts['args'] = [['']]; |
|
47 | 48 | } |
48 | - else $parts['args'] = [['']]; |
|
49 | 49 | return $parts; |
50 | 50 | } |
51 | 51 | |
52 | 52 | private function getFuncName($tokens) { |
53 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
53 | + if ($tokens->type() === Tokenizer::NAME) { |
|
54 | + return $tokens->read(); |
|
55 | + } |
|
54 | 56 | return null; |
55 | 57 | } |
56 | 58 | |
57 | 59 | public function hasFunction($name) { |
58 | 60 | foreach ($this->pseudo as $tokens) { |
59 | - if ($name === $this->getFuncName($tokens)) return true; |
|
61 | + if ($name === $this->getFuncName($tokens)) { |
|
62 | + return true; |
|
63 | + } |
|
60 | 64 | } |
61 | 65 | } |
62 | 66 | |
63 | 67 | public function getFuncArgs($name) { |
64 | 68 | foreach ($this->pseudo as $tokens) { |
65 | 69 | $parts = $this->getFuncParts($tokens); |
66 | - if ($name === $parts['name']) return $parts['args']; |
|
70 | + if ($name === $parts['name']) { |
|
71 | + return $parts['args']; |
|
72 | + } |
|
67 | 73 | } |
68 | 74 | } |
69 | 75 | } |
@@ -20,8 +20,7 @@ |
||
20 | 20 | $tokens = $args[0]; |
21 | 21 | $parser = new \Transphporm\Parser\Value($this); |
22 | 22 | $args[0] = $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
23 | - } |
|
24 | - else if ($args[0] instanceof Parser\Tokens) { |
|
23 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
25 | 24 | $args[0] = iterator_to_array($args[0]); |
26 | 25 | } |
27 | 26 | if (isset($this->functions[$name])) { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $string = $this->extractString($i); |
122 | 122 | $length = strlen($string)+1; |
123 | 123 | $char = $this->getChar($char); |
124 | - $string = str_replace('\\' . $char, $char, $string); |
|
124 | + $string = str_replace('\\'.$char, $char, $string); |
|
125 | 125 | $tokens[] = ['type' => self::STRING, 'value' => $string]; |
126 | 126 | return $length; |
127 | 127 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $str .= $chars[$token['type']]; |
165 | 165 | } |
166 | 166 | if (isset($token['value'])) { |
167 | - if ($token['value'] instanceof Tokens) $str.= $this->serialize($token['value']); |
|
167 | + if ($token['value'] instanceof Tokens) $str .= $this->serialize($token['value']); |
|
168 | 168 | else $str .= $token['value']; |
169 | 169 | } |
170 | 170 | } |
@@ -69,8 +69,11 @@ discard block |
||
69 | 69 | $i += $this->doStrings($tokens, $char, $i); |
70 | 70 | $i += $this->doBrackets($tokens, $char, $i); |
71 | 71 | } |
72 | - if ($returnObj) return new Tokens($tokens); |
|
73 | - else return $tokens; |
|
72 | + if ($returnObj) { |
|
73 | + return new Tokens($tokens); |
|
74 | + } else { |
|
75 | + return $tokens; |
|
76 | + } |
|
74 | 77 | } |
75 | 78 | |
76 | 79 | private function doSimpleTokens(&$tokens, $char) { |
@@ -93,10 +96,15 @@ discard block |
||
93 | 96 | } |
94 | 97 | |
95 | 98 | private function processLiterals(&$tokens, $name) { |
96 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
97 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
98 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
99 | - else $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
99 | + if (is_numeric($name)) { |
|
100 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
101 | + } else if ($name == 'true') { |
|
102 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
103 | + } else if ($name == 'false') { |
|
104 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
105 | + } else { |
|
106 | + $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
107 | + } |
|
100 | 108 | } |
101 | 109 | |
102 | 110 | private function doBrackets(&$tokens, $char, $i) { |
@@ -130,7 +138,9 @@ discard block |
||
130 | 138 | private function extractString($pos) { |
131 | 139 | $char = $this->str[$pos]; |
132 | 140 | $end = strpos($this->str, $char, $pos+1); |
133 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
141 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
142 | + $end = strpos($this->str, $char, $end+1); |
|
143 | + } |
|
134 | 144 | |
135 | 145 | return substr($this->str, $pos+1, $end-$pos-1); |
136 | 146 | } |
@@ -139,19 +149,27 @@ discard block |
||
139 | 149 | $close = strpos($this->str, $closeBracket, $open); |
140 | 150 | |
141 | 151 | $cPos = $open+1; |
142 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
152 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
153 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
154 | + } |
|
143 | 155 | return substr($this->str, $open+1, $close-$open-1); |
144 | 156 | } |
145 | 157 | |
146 | 158 | private function identifyChar($chr) { |
147 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
148 | - else return self::NAME; |
|
159 | + if (isset($this->chars[$chr])) { |
|
160 | + return $this->chars[$chr]; |
|
161 | + } else { |
|
162 | + return self::NAME; |
|
163 | + } |
|
149 | 164 | } |
150 | 165 | |
151 | 166 | private function getChar($num) { |
152 | 167 | $chars = array_reverse($this->chars); |
153 | - if (isset($chars[$num])) return $chars[$num]; |
|
154 | - else return false; |
|
168 | + if (isset($chars[$num])) { |
|
169 | + return $chars[$num]; |
|
170 | + } else { |
|
171 | + return false; |
|
172 | + } |
|
155 | 173 | } |
156 | 174 | |
157 | 175 | public function serialize($tokens) { |
@@ -164,8 +182,11 @@ discard block |
||
164 | 182 | $str .= $chars[$token['type']]; |
165 | 183 | } |
166 | 184 | if (isset($token['value'])) { |
167 | - if ($token['value'] instanceof Tokens) $str.= $this->serialize($token['value']); |
|
168 | - else $str .= $token['value']; |
|
185 | + if ($token['value'] instanceof Tokens) { |
|
186 | + $str.= $this->serialize($token['value']); |
|
187 | + } else { |
|
188 | + $str .= $token['value']; |
|
189 | + } |
|
169 | 190 | } |
170 | 191 | } |
171 | 192 |
@@ -49,10 +49,14 @@ discard block |
||
49 | 49 | $this->data = new ValueData($data ? $data : $this->baseData); |
50 | 50 | $this->last = null; |
51 | 51 | |
52 | - if (count($tokens) <= 0) return [$data]; |
|
52 | + if (count($tokens) <= 0) { |
|
53 | + return [$data]; |
|
54 | + } |
|
53 | 55 | |
54 | 56 | foreach ($tokens as $token) { |
55 | - if ($token['type'] !== Tokenizer::WHITESPACE) $this->{$this->tokenFuncs[$token['type']]}($token); |
|
57 | + if ($token['type'] !== Tokenizer::WHITESPACE) { |
|
58 | + $this->{$this->tokenFuncs[$token['type']]}($token); |
|
59 | + } |
|
56 | 60 | } |
57 | 61 | |
58 | 62 | $this->processLast(); |
@@ -71,13 +75,15 @@ discard block |
||
71 | 75 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
72 | 76 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
73 | 77 | private function processDot($token) { |
74 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
75 | - else { |
|
78 | + if ($this->last !== null) { |
|
79 | + $this->data->traverse($this->last); |
|
80 | + } else { |
|
76 | 81 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
77 | 82 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
78 | 83 | $lastResult = $this->result->pop(); |
79 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
80 | - else { |
|
84 | + if ($lastResult) { |
|
85 | + $this->data = new ValueData($lastResult); |
|
86 | + } else { |
|
81 | 87 | $this->processString(['value' => '.']); |
82 | 88 | $this->result->setMode(Tokenizer::CONCAT); |
83 | 89 | } |
@@ -90,9 +96,10 @@ discard block |
||
90 | 96 | $parser = new Value($this->baseData, $this->autoLookup); |
91 | 97 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
92 | 98 | $this->callTransphpormFunctions($token); |
93 | - } |
|
94 | - else { |
|
95 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
99 | + } else { |
|
100 | + if ($this->last !== null) { |
|
101 | + $this->data->traverse($this->last); |
|
102 | + } |
|
96 | 103 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
97 | 104 | } |
98 | 105 | } |
@@ -112,8 +119,7 @@ discard block |
||
112 | 119 | private function processBrackets($token) { |
113 | 120 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
114 | 121 | $this->callTransphpormFunctions($token); |
115 | - } |
|
116 | - else { |
|
122 | + } else { |
|
117 | 123 | $this->processNested($token); |
118 | 124 | } |
119 | 125 | } |
@@ -130,7 +136,9 @@ discard block |
||
130 | 136 | foreach ($this->result->getResult() as $i => $value) { |
131 | 137 | if (is_scalar($value)) { |
132 | 138 | $val = $this->data->read($value); |
133 | - if ($val) $this->result[$i] = $val; |
|
139 | + if ($val) { |
|
140 | + $this->result[$i] = $val; |
|
141 | + } |
|
134 | 142 | } |
135 | 143 | } |
136 | 144 | $this->last = null; |
@@ -142,12 +150,10 @@ discard block |
||
142 | 150 | try { |
143 | 151 | $value = $this->data->extract($this->last, $this->autoLookup); |
144 | 152 | $this->result->processValue($value); |
145 | - } |
|
146 | - catch (\UnexpectedValueException $e) { |
|
153 | + } catch (\UnexpectedValueException $e) { |
|
147 | 154 | if (!$this->autoLookup) { |
148 | 155 | $this->result->processValue($this->last); |
149 | - } |
|
150 | - else { |
|
156 | + } else { |
|
151 | 157 | $this->result->clear(); |
152 | 158 | $this->result[0] = false; |
153 | 159 | } |