@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
17 | - if (!$this->shouldRun($element)) return false; |
|
17 | + if (!$this->shouldRun($element)) { |
|
18 | + return false; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $values = $this->formatter->format($values, $rules); |
20 | 22 | |
@@ -22,14 +24,19 @@ discard block |
||
22 | 24 | //Remove the current contents |
23 | 25 | $this->removeAllChildren($element); |
24 | 26 | //Now make a text node |
25 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
26 | - else $this->appendContent($element, $values); |
|
27 | + if ($this->getContentMode($rules) === 'replace') { |
|
28 | + $this->replaceContent($element, $values); |
|
29 | + } else { |
|
30 | + $this->appendContent($element, $values); |
|
31 | + } |
|
27 | 32 | } |
28 | 33 | } |
29 | 34 | |
30 | 35 | private function shouldRun($element) { |
31 | 36 | do { |
32 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
37 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
38 | + return false; |
|
39 | + } |
|
33 | 40 | } |
34 | 41 | while (($element = $element->parentNode) instanceof \DomElement); |
35 | 42 | return true; |
@@ -56,9 +63,10 @@ discard block |
||
56 | 63 | public function getNode($node, $document) { |
57 | 64 | foreach ($node as $n) { |
58 | 65 | if (is_array($n)) { |
59 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
60 | - } |
|
61 | - else { |
|
66 | + foreach ($this->getNode($n, $document) as $new) { |
|
67 | + yield $new; |
|
68 | + } |
|
69 | + } else { |
|
62 | 70 | yield $this->convertNode($n, $document); |
63 | 71 | } |
64 | 72 | } |
@@ -69,9 +77,10 @@ discard block |
||
69 | 77 | $new = $document->importNode($node, true); |
70 | 78 | //Removing this might cause problems with caching... |
71 | 79 | //$new->setAttribute('transphporm', 'added'); |
72 | - } |
|
73 | - else { |
|
74 | - if ($node instanceof \DomText) $node = $node->nodeValue; |
|
80 | + } else { |
|
81 | + if ($node instanceof \DomText) { |
|
82 | + $node = $node->nodeValue; |
|
83 | + } |
|
75 | 84 | $new = $document->createElement('text'); |
76 | 85 | |
77 | 86 | $new->appendChild($document->createTextNode($node)); |
@@ -95,6 +104,8 @@ discard block |
||
95 | 104 | } |
96 | 105 | |
97 | 106 | private function removeAllChildren($element) { |
98 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
107 | + while ($element->hasChildNodes()) { |
|
108 | + $element->removeChild($element->firstChild); |
|
109 | + } |
|
99 | 110 | } |
100 | 111 | } |
@@ -68,7 +68,9 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
71 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
71 | + if (isset($this->properties['content'])) { |
|
72 | + $this->properties['content']->addContentPseudo($name, $pseudo); |
|
73 | + } |
|
72 | 74 | } |
73 | 75 | |
74 | 76 | public function registerPseudo(Pseudo $pseudo) { |
@@ -76,12 +78,16 @@ discard block |
||
76 | 78 | } |
77 | 79 | |
78 | 80 | public function loadProperties(Hook\PropertyHook $hook) { |
79 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
81 | + foreach ($this->properties as $name => $property) { |
|
82 | + $hook->registerProperty($name, $property); |
|
83 | + } |
|
80 | 84 | } |
81 | 85 | |
82 | 86 | public function createPseudoMatcher($pseudo) { |
83 | 87 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
84 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
88 | + foreach ($this->pseudo as $pseudoFunction) { |
|
89 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
90 | + } |
|
85 | 91 | return $pseudoMatcher; |
86 | 92 | } |
87 | 93 |
@@ -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(Pseudo $pseudo) { |
76 | 76 | $this->pseudo[] = $pseudo; |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
67 | 67 | private function processHooks() { |
68 | 68 | foreach ($this->hooks as list($query, $hook)) { |
69 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
69 | + foreach ($this->xpath->query($query) as $element) { |
|
70 | + $hook->run($element); |
|
71 | + } |
|
70 | 72 | } |
71 | 73 | $this->hooks = []; |
72 | 74 | } |
@@ -74,7 +76,9 @@ discard block |
||
74 | 76 | /** Prints out the current DomDocument as HTML */ |
75 | 77 | private function printDocument() { |
76 | 78 | $output = ''; |
77 | - foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node); |
|
79 | + foreach ($this->document->documentElement->childNodes as $node) { |
|
80 | + $output .= call_user_func($this->save, $node); |
|
81 | + } |
|
78 | 82 | return $output; |
79 | 83 | } |
80 | 84 | |
@@ -86,13 +90,18 @@ discard block |
||
86 | 90 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
87 | 91 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
88 | 92 | //Either return a whole DomDocument or return the output HTML |
89 | - if ($document) return $this->document; |
|
93 | + if ($document) { |
|
94 | + return $this->document; |
|
95 | + } |
|
90 | 96 | |
91 | 97 | //Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument |
92 | 98 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
93 | 99 | |
94 | - if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
|
95 | - else $output = $this->printDocument(); |
|
100 | + if ($this->document->documentElement->tagName !== 'template') { |
|
101 | + $output .= call_user_func($this->save, $this->document->documentElement); |
|
102 | + } else { |
|
103 | + $output = $this->printDocument(); |
|
104 | + } |
|
96 | 105 | |
97 | 106 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
98 | 107 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->save = function($content = null) { |
38 | 38 | return $this->document->saveHtml($content); |
39 | 39 | }; |
40 | - $this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
40 | + $this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
41 | 41 | |
42 | 42 | if (strpos($doc, '<!') !== 0) { |
43 | 43 | $templateNode = $this->document->getElementsByTagName('template')[0]; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if ($document) return $this->document; |
90 | 90 | |
91 | 91 | //Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument |
92 | - $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
|
92 | + $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : ''; |
|
93 | 93 | |
94 | 94 | if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
95 | 95 | else $output = $this->printDocument(); |
@@ -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 | return (new Parser\Tokenizer($tss))->getTokens(); |
48 | 54 | } |
49 | 55 | } |
@@ -7,48 +7,48 @@ |
||
7 | 7 | namespace Transphporm; |
8 | 8 | use Transphporm\Parser\Tokenizer; |
9 | 9 | class TSSValidator { |
10 | - private $error; |
|
10 | + private $error; |
|
11 | 11 | |
12 | - public function validate($tss) { |
|
13 | - $this->error = null; |
|
14 | - $tokens = $this->tokenize($tss); |
|
12 | + public function validate($tss) { |
|
13 | + $this->error = null; |
|
14 | + $tokens = $this->tokenize($tss); |
|
15 | 15 | |
16 | - foreach ($tokens as $token) |
|
17 | - if (!$this->validateRule($token)) return false; |
|
16 | + foreach ($tokens as $token) |
|
17 | + if (!$this->validateRule($token)) return false; |
|
18 | 18 | |
19 | - return true; |
|
20 | - } |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | |
22 | - public function getLastError() { |
|
23 | - return $this->error; |
|
24 | - } |
|
22 | + public function getLastError() { |
|
23 | + return $this->error; |
|
24 | + } |
|
25 | 25 | |
26 | - private function validateRule($token) { |
|
27 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
26 | + private function validateRule($token) { |
|
27 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
28 | 28 | |
29 | - return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
30 | - && $this->checkParenthesis($token); |
|
31 | - } |
|
29 | + return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
30 | + && $this->checkParenthesis($token); |
|
31 | + } |
|
32 | 32 | |
33 | - private function checkBraces($token) { |
|
34 | - return strpos($token['string'], '{') === false; |
|
35 | - } |
|
33 | + private function checkBraces($token) { |
|
34 | + return strpos($token['string'], '{') === false; |
|
35 | + } |
|
36 | 36 | |
37 | - private function checkSemicolons($braceToken) { |
|
38 | - $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
39 | - array_shift($splitTokens); array_pop($splitTokens); |
|
40 | - foreach ($splitTokens as $tokens) |
|
41 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
37 | + private function checkSemicolons($braceToken) { |
|
38 | + $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
39 | + array_shift($splitTokens); array_pop($splitTokens); |
|
40 | + foreach ($splitTokens as $tokens) |
|
41 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
42 | 42 | |
43 | - return true; |
|
44 | - } |
|
43 | + return true; |
|
44 | + } |
|
45 | 45 | |
46 | - private function checkParenthesis($token) { |
|
47 | - return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
48 | - } |
|
46 | + private function checkParenthesis($token) { |
|
47 | + return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
48 | + } |
|
49 | 49 | |
50 | - private function tokenize($tss) { |
|
51 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
52 | - return (new Parser\Tokenizer($tss))->getTokens(); |
|
53 | - } |
|
50 | + private function tokenize($tss) { |
|
51 | + if (is_file($tss)) $tss = file_get_contents($tss); |
|
52 | + return (new Parser\Tokenizer($tss))->getTokens(); |
|
53 | + } |
|
54 | 54 | } |
@@ -13,6 +13,9 @@ |
||
13 | 13 | private $functionSet; |
14 | 14 | private $id; |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $id |
|
18 | + */ |
|
16 | 19 | public function __construct(\Transphporm\FunctionSet $functionSet, $prefix = '', $id = null) { |
17 | 20 | $this->id = $id; |
18 | 21 | self::$instances[$this->id] = $this; |
@@ -70,7 +70,9 @@ discard block |
||
70 | 70 | $selector->type = $token['type']; |
71 | 71 | $selectors[] = $selector; |
72 | 72 | } |
73 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
73 | + if (isset($token['value'])) { |
|
74 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
75 | + } |
|
74 | 76 | } |
75 | 77 | return $selectors; |
76 | 78 | } |
@@ -80,7 +82,9 @@ discard block |
||
80 | 82 | $selectors = $this->split($css); |
81 | 83 | $xpath = '/'; |
82 | 84 | foreach ($selectors as $selector) { |
83 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
85 | + if (isset($this->translators[$selector->type])) { |
|
86 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
87 | + } |
|
84 | 88 | } |
85 | 89 | |
86 | 90 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -92,11 +96,15 @@ discard block |
||
92 | 96 | $tokens = new Tokens; |
93 | 97 | $split = $css->splitOnToken(Tokenizer::GREATER_THAN); |
94 | 98 | |
95 | - if (count($split) <= 1) return $css; |
|
99 | + if (count($split) <= 1) { |
|
100 | + return $css; |
|
101 | + } |
|
96 | 102 | |
97 | 103 | for ($i = 0; $i < count($split); $i++) { |
98 | 104 | $tokens->add($split[$i]->trim()); |
99 | - if (isset($split[$i+1])) $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
105 | + if (isset($split[$i+1])) { |
|
106 | + $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
107 | + } |
|
100 | 108 | } |
101 | 109 | |
102 | 110 | return $tokens; |
@@ -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) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $this->id . '")' . ']'; } |
|
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) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$this->id.'")'.']'; } |
|
29 | 29 | ]; |
30 | 30 | } |
31 | 31 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $functionSet->setElement($element[0]); |
45 | 45 | |
46 | 46 | $attributes = []; |
47 | - foreach($element[0]->attributes as $name => $node) { |
|
47 | + foreach ($element[0]->attributes as $name => $node) { |
|
48 | 48 | $attributes[$name] = $node->nodeValue; |
49 | 49 | } |
50 | 50 |
@@ -87,7 +87,7 @@ |
||
87 | 87 | if ($token['type'] === $tokenType) $i++; |
88 | 88 | else $splitTokens[$i][] = $token; |
89 | 89 | } |
90 | - return array_map(function ($tokens) { |
|
90 | + return array_map(function($tokens) { |
|
91 | 91 | return new Tokens($tokens); |
92 | 92 | }, $splitTokens); |
93 | 93 | //return $splitTokens; |
@@ -39,8 +39,11 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | public function add($token) { |
42 | - if ($token instanceof Tokens) $this->tokens = array_merge($token->tokens); |
|
43 | - else $this->tokens[] = $token; |
|
42 | + if ($token instanceof Tokens) { |
|
43 | + $this->tokens = array_merge($token->tokens); |
|
44 | + } else { |
|
45 | + $this->tokens[] = $token; |
|
46 | + } |
|
44 | 47 | } |
45 | 48 | |
46 | 49 | |
@@ -54,9 +57,13 @@ discard block |
||
54 | 57 | |
55 | 58 | private function getKeyToSlice($tokenType) { |
56 | 59 | $keys = $this->getKeysOfTokenType($tokenType); |
57 | - if (empty($keys)) return false; |
|
60 | + if (empty($keys)) { |
|
61 | + return false; |
|
62 | + } |
|
58 | 63 | $key = $keys[0]; |
59 | - for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i]; |
|
64 | + for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) { |
|
65 | + $key = $keys[$i]; |
|
66 | + } |
|
60 | 67 | return $key; |
61 | 68 | } |
62 | 69 | |
@@ -70,10 +77,17 @@ discard block |
||
70 | 77 | |
71 | 78 | private function sliceTokens($tokenType, $type, $increment = false) { |
72 | 79 | $key = $this->getKeyToSlice($tokenType); |
73 | - if ($key === false) return new Tokens([]); |
|
74 | - if ($increment) $key++; |
|
75 | - if ($type === "from") return new Tokens(array_slice($this->tokens, $key)); |
|
76 | - else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
80 | + if ($key === false) { |
|
81 | + return new Tokens([]); |
|
82 | + } |
|
83 | + if ($increment) { |
|
84 | + $key++; |
|
85 | + } |
|
86 | + if ($type === "from") { |
|
87 | + return new Tokens(array_slice($this->tokens, $key)); |
|
88 | + } else { |
|
89 | + return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
90 | + } |
|
77 | 91 | } |
78 | 92 | |
79 | 93 | public function skip($count) { |
@@ -84,8 +98,11 @@ discard block |
||
84 | 98 | $splitTokens = []; |
85 | 99 | $i = 0; |
86 | 100 | foreach ($this->tokens as $token) { |
87 | - if ($token['type'] === $tokenType) $i++; |
|
88 | - else $splitTokens[$i][] = $token; |
|
101 | + if ($token['type'] === $tokenType) { |
|
102 | + $i++; |
|
103 | + } else { |
|
104 | + $splitTokens[$i][] = $token; |
|
105 | + } |
|
89 | 106 | } |
90 | 107 | return array_map(function ($tokens) { |
91 | 108 | return new Tokens($tokens); |
@@ -109,7 +126,9 @@ discard block |
||
109 | 126 | |
110 | 127 | public function removeLine() { |
111 | 128 | $tokens = $this->tokens; |
112 | - foreach ($tokens as &$token) unset($token['line']); |
|
129 | + foreach ($tokens as &$token) { |
|
130 | + unset($token['line']); |
|
131 | + } |
|
113 | 132 | return new Tokens($tokens); |
114 | 133 | } |
115 | 134 |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | public function read($offset = 0) { |
58 | - return $this->str[$this->pos + $offset]; |
|
58 | + return $this->str[$this->pos+$offset]; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function identifyChar($offset = 0) { |
62 | - $chr = $this->str[$this->pos + $offset]; |
|
62 | + $chr = $this->str[$this->pos+$offset]; |
|
63 | 63 | if (!empty($this->chars[$chr])) return $this->chars[$chr]; |
64 | 64 | else return Tokenizer::NAME; |
65 | 65 | } |
66 | 66 | |
67 | 67 | public function has($offset = 0) { |
68 | - return isset($this->str[$this->pos + $offset]); |
|
68 | + return isset($this->str[$this->pos+$offset]); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | public function pos($str) { |
72 | - $pos = strpos($this->str, $str, $this->pos); |
|
72 | + $pos = strpos($this->str, $str, $this->pos); |
|
73 | 73 | return $pos ? $pos-$this->pos : false; |
74 | 74 | } |
75 | 75 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | public function extractString($offset = 0) { |
85 | - $pos = $this->pos + $offset; |
|
85 | + $pos = $this->pos+$offset; |
|
86 | 86 | $char = $this->str[$pos]; |
87 | 87 | $end = strpos($this->str, $char, $pos+1); |
88 | 88 | while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
@@ -40,8 +40,11 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | public function move($n) { |
43 | - if ($n === false) $this->pos = strlen($this->str)-1; |
|
44 | - else $this->pos += $n; |
|
43 | + if ($n === false) { |
|
44 | + $this->pos = strlen($this->str)-1; |
|
45 | + } else { |
|
46 | + $this->pos += $n; |
|
47 | + } |
|
45 | 48 | } |
46 | 49 | |
47 | 50 | public function next() { |
@@ -60,8 +63,11 @@ discard block |
||
60 | 63 | |
61 | 64 | public function identifyChar($offset = 0) { |
62 | 65 | $chr = $this->str[$this->pos + $offset]; |
63 | - if (!empty($this->chars[$chr])) return $this->chars[$chr]; |
|
64 | - else return Tokenizer::NAME; |
|
66 | + if (!empty($this->chars[$chr])) { |
|
67 | + return $this->chars[$chr]; |
|
68 | + } else { |
|
69 | + return Tokenizer::NAME; |
|
70 | + } |
|
65 | 71 | } |
66 | 72 | |
67 | 73 | public function has($offset = 0) { |
@@ -85,7 +91,9 @@ discard block |
||
85 | 91 | $pos = $this->pos + $offset; |
86 | 92 | $char = $this->str[$pos]; |
87 | 93 | $end = strpos($this->str, $char, $pos+1); |
88 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
94 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
95 | + $end = strpos($this->str, $char, $end+1); |
|
96 | + } |
|
89 | 97 | |
90 | 98 | return substr($this->str, $pos+1, $end-$pos-1); |
91 | 99 | } |
@@ -95,7 +103,9 @@ discard block |
||
95 | 103 | $close = strpos($this->str, $closeBracket, $open); |
96 | 104 | |
97 | 105 | $cPos = $open+1; |
98 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
106 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
107 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
108 | + } |
|
99 | 109 | return substr($this->str, $open+1, $close-$open-1); |
100 | 110 | } |
101 | 111 |
@@ -5,7 +5,7 @@ |
||
5 | 5 | |
6 | 6 | class Brackets implements \Transphporm\Parser\Tokenize { |
7 | 7 | |
8 | - private $types = [ |
|
8 | + private $types = [ |
|
9 | 9 | Tokenizer::OPEN_BRACKET => ['(', ')'], |
10 | 10 | Tokenizer::OPEN_BRACE => ['{', '}'], |
11 | 11 | Tokenizer::OPEN_SQUARE_BRACKET => ['[', ']'] |
@@ -32,9 +32,14 @@ |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | private function processLiterals($tokens, $name, $str) { |
35 | - if (is_numeric($name)) $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
36 | - else if ($name == 'true') $tokens->add(['type' => Tokenizer::BOOL, 'value' => true]); |
|
37 | - else if ($name == 'false') $tokens->add(['type' => Tokenizer::BOOL, 'value' => false]); |
|
38 | - else $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
35 | + if (is_numeric($name)) { |
|
36 | + $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
37 | + } else if ($name == 'true') { |
|
38 | + $tokens->add(['type' => Tokenizer::BOOL, 'value' => true]); |
|
39 | + } else if ($name == 'false') { |
|
40 | + $tokens->add(['type' => Tokenizer::BOOL, 'value' => false]); |
|
41 | + } else { |
|
42 | + $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
43 | + } |
|
39 | 44 | } |
40 | 45 | } |
41 | 46 | \ No newline at end of file |