@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | |
29 | 29 | |
30 | 30 | public function traverse() { |
31 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
32 | - else { |
|
31 | + if ($this->last !== null) { |
|
32 | + $this->data->traverse($this->last); |
|
33 | + } else { |
|
33 | 34 | $lastResult = $this->result->pop(); |
34 | 35 | if ($lastResult) { |
35 | 36 | $this->data = new ValueData($lastResult); |
@@ -67,8 +68,7 @@ discard block |
||
67 | 68 | try { |
68 | 69 | $value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
69 | 70 | $this->result->processValue($value); |
70 | - } |
|
71 | - catch (\UnexpectedValueException $e) { |
|
71 | + } catch (\UnexpectedValueException $e) { |
|
72 | 72 | $this->processLastUnexpected(); |
73 | 73 | } |
74 | 74 | } |
@@ -77,8 +77,7 @@ discard block |
||
77 | 77 | private function processLastUnexpected() { |
78 | 78 | if (!($this->autoLookup || $this->traversing)) { |
79 | 79 | $this->result->processValue($this->last); |
80 | - } |
|
81 | - else { |
|
80 | + } else { |
|
82 | 81 | $this->result->clear(); |
83 | 82 | $this->result[0] = false; |
84 | 83 | } |
@@ -145,7 +145,7 @@ |
||
145 | 145 | $string = $this->extractString($i); |
146 | 146 | $length = strlen($string)+1; |
147 | 147 | $char = $this->getChar($char); |
148 | - $string = str_replace('\\' . $char, $char, $string); |
|
148 | + $string = str_replace('\\'.$char, $char, $string); |
|
149 | 149 | $tokens[] = ['type' => self::STRING, 'value' => $string, 'line' => $this->lineNo]; |
150 | 150 | return $length; |
151 | 151 | } |
@@ -79,8 +79,11 @@ discard block |
||
79 | 79 | $i += $this->doStrings($tokens, $char, $i); |
80 | 80 | $i += $this->doBrackets($tokens, $char, $i); |
81 | 81 | } |
82 | - if ($returnObj) return new Tokens($tokens); |
|
83 | - else return $tokens; |
|
82 | + if ($returnObj) { |
|
83 | + return new Tokens($tokens); |
|
84 | + } else { |
|
85 | + return $tokens; |
|
86 | + } |
|
84 | 87 | } |
85 | 88 | |
86 | 89 | private function doSimpleTokens(&$tokens, $char) { |
@@ -117,10 +120,15 @@ discard block |
||
117 | 120 | } |
118 | 121 | |
119 | 122 | private function processLiterals(&$tokens, $name) { |
120 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
121 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
122 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
123 | - else $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo]; |
|
123 | + if (is_numeric($name)) { |
|
124 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
125 | + } else if ($name == 'true') { |
|
126 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
127 | + } else if ($name == 'false') { |
|
128 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
129 | + } else { |
|
130 | + $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo]; |
|
131 | + } |
|
124 | 132 | } |
125 | 133 | |
126 | 134 | private function doBrackets(&$tokens, $char, $i) { |
@@ -154,7 +162,9 @@ discard block |
||
154 | 162 | private function extractString($pos) { |
155 | 163 | $char = $this->str[$pos]; |
156 | 164 | $end = strpos($this->str, $char, $pos+1); |
157 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
165 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
166 | + $end = strpos($this->str, $char, $end+1); |
|
167 | + } |
|
158 | 168 | |
159 | 169 | return substr($this->str, $pos+1, $end-$pos-1); |
160 | 170 | } |
@@ -163,18 +173,26 @@ discard block |
||
163 | 173 | $close = strpos($this->str, $closeBracket, $open); |
164 | 174 | |
165 | 175 | $cPos = $open+1; |
166 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
176 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
177 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
178 | + } |
|
167 | 179 | return substr($this->str, $open+1, $close-$open-1); |
168 | 180 | } |
169 | 181 | |
170 | 182 | private function identifyChar($chr) { |
171 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
172 | - else return self::NAME; |
|
183 | + if (isset($this->chars[$chr])) { |
|
184 | + return $this->chars[$chr]; |
|
185 | + } else { |
|
186 | + return self::NAME; |
|
187 | + } |
|
173 | 188 | } |
174 | 189 | |
175 | 190 | private function getChar($num) { |
176 | 191 | $chars = array_reverse($this->chars); |
177 | - if (isset($chars[$num])) return $chars[$num]; |
|
178 | - else return false; |
|
192 | + if (isset($chars[$num])) { |
|
193 | + return $chars[$num]; |
|
194 | + } else { |
|
195 | + return false; |
|
196 | + } |
|
179 | 197 | } |
180 | 198 | } |
@@ -2,55 +2,55 @@ |
||
2 | 2 | namespace Transphporm; |
3 | 3 | use Transphporm\Parser\Tokenizer; |
4 | 4 | class TSSValidator { |
5 | - private $error; |
|
5 | + private $error; |
|
6 | 6 | |
7 | - public function validate($tss) { |
|
8 | - $this->error = null; |
|
9 | - $tokens = $this->tokenize($tss); |
|
7 | + public function validate($tss) { |
|
8 | + $this->error = null; |
|
9 | + $tokens = $this->tokenize($tss); |
|
10 | 10 | |
11 | - foreach ($tokens as $token) |
|
12 | - if (!$this->validateRule($token)) return false; |
|
11 | + foreach ($tokens as $token) |
|
12 | + if (!$this->validateRule($token)) return false; |
|
13 | 13 | |
14 | - return true; |
|
15 | - } |
|
14 | + return true; |
|
15 | + } |
|
16 | 16 | |
17 | - public function getLastError() { |
|
18 | - return $this->error; |
|
19 | - } |
|
17 | + public function getLastError() { |
|
18 | + return $this->error; |
|
19 | + } |
|
20 | 20 | |
21 | - private function validateRule($token) { |
|
22 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
21 | + private function validateRule($token) { |
|
22 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
23 | 23 | |
24 | - return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
25 | - && $this->checkParenthesis($token); |
|
26 | - } |
|
24 | + return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
25 | + && $this->checkParenthesis($token); |
|
26 | + } |
|
27 | 27 | |
28 | - private function checkBraces($token) { |
|
29 | - return strpos($token['string'], '{') === false; |
|
30 | - } |
|
28 | + private function checkBraces($token) { |
|
29 | + return strpos($token['string'], '{') === false; |
|
30 | + } |
|
31 | 31 | |
32 | - private function checkSemicolons($braceToken) { |
|
33 | - $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
34 | - array_shift($splitTokens); array_pop($splitTokens); |
|
35 | - foreach ($splitTokens as $tokens) |
|
36 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
32 | + private function checkSemicolons($braceToken) { |
|
33 | + $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
34 | + array_shift($splitTokens); array_pop($splitTokens); |
|
35 | + foreach ($splitTokens as $tokens) |
|
36 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
37 | 37 | |
38 | - return true; |
|
39 | - } |
|
38 | + return true; |
|
39 | + } |
|
40 | 40 | |
41 | - private function checkParenthesis($token) { |
|
42 | - return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
43 | - } |
|
41 | + private function checkParenthesis($token) { |
|
42 | + return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
43 | + } |
|
44 | 44 | |
45 | - private function tokenize($tss) { |
|
46 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
47 | - $tss = $this->stripComments($tss, '//', "\n"); |
|
45 | + private function tokenize($tss) { |
|
46 | + if (is_file($tss)) $tss = file_get_contents($tss); |
|
47 | + $tss = $this->stripComments($tss, '//', "\n"); |
|
48 | 48 | $tss = $this->stripComments($tss, '/*', '*/'); |
49 | 49 | $tokenizer = new Tokenizer($tss); |
50 | 50 | return $tokenizer->getTokens(); |
51 | - } |
|
51 | + } |
|
52 | 52 | |
53 | - private function stripComments($str, $open, $close) { |
|
53 | + private function stripComments($str, $open, $close) { |
|
54 | 54 | $pos = 0; |
55 | 55 | while (($pos = strpos($str, $open, $pos)) !== false) { |
56 | 56 | $end = strpos($str, $close, $pos); |
@@ -8,8 +8,9 @@ discard block |
||
8 | 8 | $this->error = null; |
9 | 9 | $tokens = $this->tokenize($tss); |
10 | 10 | |
11 | - foreach ($tokens as $token) |
|
12 | - if (!$this->validateRule($token)) return false; |
|
11 | + foreach ($tokens as $token) { |
|
12 | + if (!$this->validateRule($token)) return false; |
|
13 | + } |
|
13 | 14 | |
14 | 15 | return true; |
15 | 16 | } |
@@ -19,7 +20,9 @@ discard block |
||
19 | 20 | } |
20 | 21 | |
21 | 22 | private function validateRule($token) { |
22 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
23 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) { |
|
24 | + return true; |
|
25 | + } |
|
23 | 26 | |
24 | 27 | return $this->checkBraces($token) && $this->checkSemicolons($token) |
25 | 28 | && $this->checkParenthesis($token); |
@@ -32,8 +35,9 @@ discard block |
||
32 | 35 | private function checkSemicolons($braceToken) { |
33 | 36 | $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
34 | 37 | array_shift($splitTokens); array_pop($splitTokens); |
35 | - foreach ($splitTokens as $tokens) |
|
36 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
38 | + foreach ($splitTokens as $tokens) { |
|
39 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
40 | + } |
|
37 | 41 | |
38 | 42 | return true; |
39 | 43 | } |
@@ -43,7 +47,9 @@ discard block |
||
43 | 47 | } |
44 | 48 | |
45 | 49 | private function tokenize($tss) { |
46 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
50 | + if (is_file($tss)) { |
|
51 | + $tss = file_get_contents($tss); |
|
52 | + } |
|
47 | 53 | $tss = $this->stripComments($tss, '//', "\n"); |
48 | 54 | $tss = $this->stripComments($tss, '/*', '*/'); |
49 | 55 | $tokenizer = new Tokenizer($tss); |
@@ -54,7 +60,9 @@ discard block |
||
54 | 60 | $pos = 0; |
55 | 61 | while (($pos = strpos($str, $open, $pos)) !== false) { |
56 | 62 | $end = strpos($str, $close, $pos); |
57 | - if ($end === false) break; |
|
63 | + if ($end === false) { |
|
64 | + break; |
|
65 | + } |
|
58 | 66 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
59 | 67 | } |
60 | 68 |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | if (isset($this->functions[$name])) { |
21 | 21 | return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element); |
22 | 22 | } |
23 | - } |
|
24 | - catch (\Exception $e) { |
|
23 | + } catch (\Exception $e) { |
|
25 | 24 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
26 | 25 | } |
27 | 26 | return false; |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | $tokens = $args[0]; |
33 | 32 | $parser = new \Transphporm\Parser\Value($this); |
34 | 33 | return $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
35 | - } |
|
36 | - else if ($args[0] instanceof Parser\Tokens) { |
|
34 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
37 | 35 | return iterator_to_array($args[0]); |
38 | 36 | } |
39 | 37 |
@@ -7,11 +7,11 @@ discard block |
||
7 | 7 | namespace Transphporm\Pseudo; |
8 | 8 | class Not implements \Transphporm\Pseudo { |
9 | 9 | private $cssToXpath; |
10 | - private $config; |
|
10 | + private $config; |
|
11 | 11 | |
12 | 12 | public function __construct(\Transphporm\Parser\CssToXpath $cssToXpath, \Transphporm\Config $config) { |
13 | 13 | $this->cssToXpath = $cssToXpath; |
14 | - $this->config = $config; |
|
14 | + $this->config = $config; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | foreach ($css as $selector) { |
27 | 27 | $tokenizer = new \Transphporm\Parser\Tokenizer($selector); |
28 | 28 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | - $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | - $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
29 | + $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | + $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
31 | 31 | if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
32 | 32 | } |
33 | 33 | return true; |
34 | 34 | } |
35 | 35 | |
36 | - private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | - //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | - foreach ($foundElements as $matchedElement) { |
|
39 | - //Check to see whether this node was matched by the not query |
|
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | - } |
|
42 | - return false; |
|
43 | - } |
|
36 | + private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | + //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | + foreach ($foundElements as $matchedElement) { |
|
39 | + //Check to see whether this node was matched by the not query |
|
40 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | + } |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | } |
@@ -15,7 +15,9 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
18 | - if ($name !== 'not') return true; |
|
18 | + if ($name !== 'not') { |
|
19 | + return true; |
|
20 | + } |
|
19 | 21 | |
20 | 22 | $xpath = new \DomXpath($element->ownerDocument); |
21 | 23 | return $this->notElement($args, $xpath, $element); |
@@ -28,7 +30,9 @@ discard block |
||
28 | 30 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | 31 | $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
30 | 32 | $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
31 | - if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
|
33 | + if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) { |
|
34 | + return false; |
|
35 | + } |
|
32 | 36 | } |
33 | 37 | return true; |
34 | 38 | } |
@@ -37,7 +41,9 @@ discard block |
||
37 | 41 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
38 | 42 | foreach ($foundElements as $matchedElement) { |
39 | 43 | //Check to see whether this node was matched by the not query |
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
44 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) { |
|
45 | + return true; |
|
46 | + } |
|
41 | 47 | } |
42 | 48 | return false; |
43 | 49 | } |
@@ -8,6 +8,9 @@ |
||
8 | 8 | $this->paths[] = rtrim($path, DIRECTORY_SEPARATOR); |
9 | 9 | } |
10 | 10 | |
11 | + /** |
|
12 | + * @param string $baseDir |
|
13 | + */ |
|
11 | 14 | public function setBaseDir($baseDir) { |
12 | 15 | $this->baseDir = $baseDir; |
13 | 16 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | |
15 | 15 | public function getFilePath($filePath) { |
16 | 16 | if (is_file($filePath)) return $filePath; |
17 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
17 | + else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath; |
|
18 | 18 | else return $this->loadFromPaths($filePath); |
19 | 19 | |
20 | - throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths)); |
|
20 | + throw new \Exception($filePath.' not found in include path: '.implode(';', $this->paths)); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | private function loadFromPaths($filePath) { |
24 | 24 | foreach ($this->paths as $path) { |
25 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
25 | + if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | } |
@@ -13,16 +13,22 @@ |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function getFilePath($filePath) { |
16 | - if (is_file($filePath)) return $filePath; |
|
17 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
18 | - else return $this->loadFromPaths($filePath); |
|
16 | + if (is_file($filePath)) { |
|
17 | + return $filePath; |
|
18 | + } else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) { |
|
19 | + return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
20 | + } else { |
|
21 | + return $this->loadFromPaths($filePath); |
|
22 | + } |
|
19 | 23 | |
20 | 24 | throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths)); |
21 | 25 | } |
22 | 26 | |
23 | 27 | private function loadFromPaths($filePath) { |
24 | 28 | foreach ($this->paths as $path) { |
25 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
29 | + if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) { |
|
30 | + return $path . DIRECTORY_SEPARATOR . $filePath; |
|
31 | + } |
|
26 | 32 | } |
27 | 33 | } |
28 | 34 | } |
@@ -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; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
35 | 35 | $this->functionSet->setElement($element); |
36 | 36 | $this->configLine = $this->line; |
37 | 37 | try { |
@@ -31,15 +31,18 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) { |
|
35 | + $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
36 | + } |
|
35 | 37 | $this->functionSet->setElement($element); |
36 | 38 | $this->configLine = $this->line; |
37 | 39 | try { |
38 | 40 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
39 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
41 | + if (!$this->pseudoMatcher->matches($element)) { |
|
42 | + return; |
|
43 | + } |
|
40 | 44 | $this->callProperties($element); |
41 | - } |
|
42 | - catch (\Transphporm\RunException $e) { |
|
45 | + } catch (\Transphporm\RunException $e) { |
|
43 | 46 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
44 | 47 | } |
45 | 48 | } |
@@ -50,7 +53,9 @@ discard block |
||
50 | 53 | private function callProperties($element) { |
51 | 54 | foreach ($this->rules as $name => $value) { |
52 | 55 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
53 | - if ($result === false) break; |
|
56 | + if ($result === false) { |
|
57 | + break; |
|
58 | + } |
|
54 | 59 | } |
55 | 60 | } |
56 | 61 | private function getArgs($value) { |
@@ -65,9 +70,10 @@ discard block |
||
65 | 70 | if (isset($this->properties[$name])) { |
66 | 71 | try { |
67 | 72 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
68 | - } |
|
69 | - catch (\Exception $e) { |
|
70 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
73 | + } catch (\Exception $e) { |
|
74 | + if ($e instanceof \Transphporm\RunException) { |
|
75 | + throw $e; |
|
76 | + } |
|
71 | 77 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
72 | 78 | } |
73 | 79 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | |
70 | 70 | public function extract($last, $autoLookup, $traversing) { |
71 | 71 | $value = $this->read($last); |
72 | - if ($value !== null && ($autoLookup || $traversing) ) { |
|
72 | + if ($value !== null && ($autoLookup || $traversing)) { |
|
73 | 73 | return $value; |
74 | 74 | } |
75 | 75 | throw new \UnexpectedValueException('Not found'); |
@@ -15,13 +15,17 @@ discard block |
||
15 | 15 | |
16 | 16 | //Read $key from array, $this->data = $this->data[$key] but also works for objects |
17 | 17 | private function traverseInto($key) { |
18 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
19 | - else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
18 | + if (isset($this->data->{$key})) { |
|
19 | + $this->data = $this->data->{$key}; |
|
20 | + } else if ($this->isArray() && isset($this->data[$key])) { |
|
21 | + $this->data = $this->data[$key]; |
|
22 | + } |
|
20 | 23 | } |
21 | 24 | |
22 | 25 | public function traverse($key, $result) { |
23 | - if ($key !== null) $this->traverseInto($key); |
|
24 | - else { |
|
26 | + if ($key !== null) { |
|
27 | + $this->traverseInto($key); |
|
28 | + } else { |
|
25 | 29 | //But if the key is null, replace the data structure with the result of the last function call |
26 | 30 | $lastResult = $result->pop(); |
27 | 31 | if ($lastResult) { |
@@ -41,10 +45,14 @@ discard block |
||
41 | 45 | |
42 | 46 | public function read($value) { |
43 | 47 | if ($this->isArray()) { |
44 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
48 | + if (isset($this->data[$value])) { |
|
49 | + return $this->data[$value]; |
|
50 | + } |
|
51 | + } else if (isset($this->data->$value)) { |
|
52 | + return $this->data->$value; |
|
53 | + } else { |
|
54 | + return null; |
|
45 | 55 | } |
46 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
47 | - else return null; |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | public function call($func, $args) { |
@@ -57,14 +65,20 @@ discard block |
||
57 | 65 | |
58 | 66 | public function parseNested($parser, $token, $funcName) { |
59 | 67 | $args = $parser->parseTokens($token['value'], $this->data); |
60 | - if ($args[0] === $this->data) $args = []; |
|
68 | + if ($args[0] === $this->data) { |
|
69 | + $args = []; |
|
70 | + } |
|
61 | 71 | return $this->callFuncOnObject($this->data, $funcName, $args); |
62 | 72 | } |
63 | 73 | |
64 | 74 | private function callFuncOnObject($obj, $func, $args) { |
65 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
66 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
67 | - else return false; |
|
75 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
76 | + return call_user_func_array($obj->$func, $args); |
|
77 | + } else if (is_callable([$obj, $func])) { |
|
78 | + return call_user_func_array([$obj, $func], $args); |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
68 | 82 | } |
69 | 83 | |
70 | 84 | public function extract($last, $autoLookup, $traversing) { |