@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | public function currency($num) { |
15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
17 | - else return $num . $this->locale['currency']; |
|
16 | + if ($this->locale['currency_position'] === 'before') return $this->locale['currency'].$num; |
|
17 | + else return $num.$this->locale['currency']; |
|
18 | 18 | } |
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -13,7 +13,10 @@ |
||
13 | 13 | |
14 | 14 | public function currency($num) { |
15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
17 | - else return $num . $this->locale['currency']; |
|
16 | + if ($this->locale['currency_position'] === 'before') { |
|
17 | + return $this->locale['currency'] . $num; |
|
18 | + } else { |
|
19 | + return $num . $this->locale['currency']; |
|
20 | + } |
|
18 | 21 | } |
19 | 22 | } |
20 | 23 | \ No newline at end of file |
@@ -39,9 +39,9 @@ |
||
39 | 39 | $num = (int) $frequency; |
40 | 40 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
41 | 41 | |
42 | - $offset = $num * constant(self::class . '::' . $unit); |
|
42 | + $offset = $num * constant(self::class.'::'.$unit); |
|
43 | 43 | |
44 | - if ($time > $this->lastRun + $offset) return true; |
|
44 | + if ($time > $this->lastRun+$offset) return true; |
|
45 | 45 | else return false; |
46 | 46 | } |
47 | 47 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | private $pseudo; |
11 | 11 | private $depth; |
12 | 12 | private $index; |
13 | - private $file; |
|
13 | + private $file; |
|
14 | 14 | private $line; |
15 | 15 | private $properties = []; |
16 | 16 | private $lastRun = 0; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $this->pseudo = $pseudo; |
27 | 27 | $this->depth = $depth; |
28 | 28 | $this->index = $index; |
29 | - $this->file = $file; |
|
29 | + $this->file = $file; |
|
30 | 30 | $this->line = $line; |
31 | 31 | $this->properties = $properties; |
32 | 32 | } |
@@ -44,23 +44,32 @@ |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | private function timeFrequency($frequency, $time = null) { |
47 | - if ($time === null) $time = time(); |
|
47 | + if ($time === null) { |
|
48 | + $time = time(); |
|
49 | + } |
|
48 | 50 | $num = (int) $frequency; |
49 | 51 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
50 | 52 | |
51 | 53 | $offset = $num * constant(self::class . '::' . $unit); |
52 | 54 | |
53 | - if ($time > $this->lastRun + $offset) return true; |
|
54 | - else return false; |
|
55 | + if ($time > $this->lastRun + $offset) { |
|
56 | + return true; |
|
57 | + } else { |
|
58 | + return false; |
|
59 | + } |
|
55 | 60 | } |
56 | 61 | |
57 | 62 | public function shouldRun($time = null) { |
58 | 63 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
59 | 64 | $frequency = $this->properties['update-frequency']->read(); |
60 | 65 | $static = ['always' => true, 'never' => false]; |
61 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
62 | - else return $this->timeFrequency($frequency, $time); |
|
66 | + if (isset($static[$frequency])) { |
|
67 | + return $static[$frequency]; |
|
68 | + } else { |
|
69 | + return $this->timeFrequency($frequency, $time); |
|
70 | + } |
|
71 | + } else { |
|
72 | + return true; |
|
63 | 73 | } |
64 | - else return true; |
|
65 | 74 | } |
66 | 75 | } |
@@ -9,9 +9,13 @@ |
||
9 | 9 | class PostProcess implements \Transphporm\Hook { |
10 | 10 | public function run(\DomElement $element) { |
11 | 11 | $transphporm = $element->getAttribute('transphporm'); |
12 | - if ($transphporm === 'remove') $element->parentNode->removeChild($element); |
|
13 | - else if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element); |
|
14 | - else $element->removeAttribute('transphporm'); |
|
12 | + if ($transphporm === 'remove') { |
|
13 | + $element->parentNode->removeChild($element); |
|
14 | + } else if ($transphporm === 'text') { |
|
15 | + $element->parentNode->replaceChild($element->firstChild, $element); |
|
16 | + } else { |
|
17 | + $element->removeAttribute('transphporm'); |
|
18 | + } |
|
15 | 19 | } |
16 | 20 | |
17 | 21 | } |
18 | 22 | \ No newline at end of file |
@@ -31,7 +31,9 @@ |
||
31 | 31 | /** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/ |
32 | 32 | public function getData(\DomElement $element = null, $type = 'data') { |
33 | 33 | while ($element) { |
34 | - if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type]; |
|
34 | + if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) { |
|
35 | + return $this->elementMap[$element][$type]; |
|
36 | + } |
|
35 | 37 | $element = $element->parentNode; |
36 | 38 | } |
37 | 39 | return $this->data; |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\TSSFunction; |
8 | 8 | /* Handles data() and iteration() function calls from the stylesheet */ |
9 | -class Data implements \Transphporm\TSSFunction{ |
|
9 | +class Data implements \Transphporm\TSSFunction { |
|
10 | 10 | private $data; |
11 | 11 | private $dataKey; |
12 | 12 | private $functionSet; |
@@ -18,8 +18,11 @@ |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run(array $args, \DomElement $element = null) { |
21 | - if ($this->dataKey === "root") $data = $this->data->getData(null, 'data'); |
|
22 | - else $data = $this->data->getData($element, $this->dataKey); |
|
21 | + if ($this->dataKey === "root") { |
|
22 | + $data = $this->data->getData(null, 'data'); |
|
23 | + } else { |
|
24 | + $data = $this->data->getData($element, $this->dataKey); |
|
25 | + } |
|
23 | 26 | $parser = new \Transphporm\Parser\Value($this->functionSet, true, true); |
24 | 27 | $return = $parser->parseTokens(new \Transphporm\Parser\Tokens($args), $data); |
25 | 28 | return $return[0]; |
@@ -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 | } |
@@ -78,7 +78,7 @@ |
||
78 | 78 | if ($token['type'] === $tokenType) $i++; |
79 | 79 | else $splitTokens[$i][] = $token; |
80 | 80 | } |
81 | - return array_map(function ($tokens) { |
|
81 | + return array_map(function($tokens) { |
|
82 | 82 | return new Tokens($tokens); |
83 | 83 | }, $splitTokens); |
84 | 84 | //return $splitTokens; |
@@ -6,28 +6,28 @@ discard block |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\Parser; |
8 | 8 | class Tokens implements \Iterator, \Countable { |
9 | - private $tokens; |
|
10 | - private $iterator = 0; |
|
9 | + private $tokens; |
|
10 | + private $iterator = 0; |
|
11 | 11 | |
12 | - public function __construct(array $tokens) { |
|
13 | - $this->tokens = $tokens; |
|
14 | - } |
|
12 | + public function __construct(array $tokens) { |
|
13 | + $this->tokens = $tokens; |
|
14 | + } |
|
15 | 15 | |
16 | - public function count() { |
|
17 | - return count($this->tokens); |
|
18 | - } |
|
16 | + public function count() { |
|
17 | + return count($this->tokens); |
|
18 | + } |
|
19 | 19 | |
20 | - // Iterator Functions |
|
21 | - public function current() { |
|
22 | - return $this->tokens[$this->iterator]; |
|
23 | - } |
|
20 | + // Iterator Functions |
|
21 | + public function current() { |
|
22 | + return $this->tokens[$this->iterator]; |
|
23 | + } |
|
24 | 24 | |
25 | - public function key() { |
|
26 | - return $this->iterator; |
|
27 | - } |
|
25 | + public function key() { |
|
26 | + return $this->iterator; |
|
27 | + } |
|
28 | 28 | |
29 | - public function next() { |
|
30 | - ++$this->iterator; |
|
29 | + public function next() { |
|
30 | + ++$this->iterator; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function valid() { |
@@ -38,75 +38,75 @@ discard block |
||
38 | 38 | $this->iterator = 0; |
39 | 39 | } |
40 | 40 | |
41 | - private function getKeysOfTokenType($tokenType) { |
|
42 | - return array_keys(array_column($this->tokens, 'type'), $tokenType); |
|
43 | - } |
|
44 | - |
|
45 | - private function getKeyToSlice($tokenType) { |
|
46 | - $keys = $this->getKeysOfTokenType($tokenType); |
|
47 | - if (empty($keys)) return false; |
|
48 | - $key = $keys[0]; |
|
49 | - for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i]; |
|
50 | - return $key; |
|
51 | - } |
|
52 | - |
|
53 | - public function from($tokenType, $inclusive = false) { |
|
54 | - return $this->sliceTokens($tokenType, "from", !$inclusive); |
|
55 | - } |
|
56 | - |
|
57 | - public function to($tokenType, $inclusive = false) { |
|
58 | - return $this->sliceTokens($tokenType, "to", $inclusive); |
|
59 | - } |
|
60 | - |
|
61 | - private function sliceTokens($tokenType, $type, $increment = false) { |
|
62 | - $key = $this->getKeyToSlice($tokenType); |
|
63 | - if ($key === false) return new Tokens([]); |
|
64 | - if ($increment) $key++; |
|
65 | - if ($type === "from") return new Tokens(array_slice($this->tokens, $key)); |
|
66 | - else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
67 | - } |
|
68 | - |
|
69 | - public function skip($count) { |
|
70 | - $this->iterator += $count; |
|
71 | - } |
|
72 | - |
|
73 | - public function splitOnToken($tokenType) { |
|
74 | - $splitTokens = []; |
|
41 | + private function getKeysOfTokenType($tokenType) { |
|
42 | + return array_keys(array_column($this->tokens, 'type'), $tokenType); |
|
43 | + } |
|
44 | + |
|
45 | + private function getKeyToSlice($tokenType) { |
|
46 | + $keys = $this->getKeysOfTokenType($tokenType); |
|
47 | + if (empty($keys)) return false; |
|
48 | + $key = $keys[0]; |
|
49 | + for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i]; |
|
50 | + return $key; |
|
51 | + } |
|
52 | + |
|
53 | + public function from($tokenType, $inclusive = false) { |
|
54 | + return $this->sliceTokens($tokenType, "from", !$inclusive); |
|
55 | + } |
|
56 | + |
|
57 | + public function to($tokenType, $inclusive = false) { |
|
58 | + return $this->sliceTokens($tokenType, "to", $inclusive); |
|
59 | + } |
|
60 | + |
|
61 | + private function sliceTokens($tokenType, $type, $increment = false) { |
|
62 | + $key = $this->getKeyToSlice($tokenType); |
|
63 | + if ($key === false) return new Tokens([]); |
|
64 | + if ($increment) $key++; |
|
65 | + if ($type === "from") return new Tokens(array_slice($this->tokens, $key)); |
|
66 | + else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
67 | + } |
|
68 | + |
|
69 | + public function skip($count) { |
|
70 | + $this->iterator += $count; |
|
71 | + } |
|
72 | + |
|
73 | + public function splitOnToken($tokenType) { |
|
74 | + $splitTokens = []; |
|
75 | 75 | $i = 0; |
76 | 76 | foreach ($this->tokens as $token) { |
77 | 77 | if ($token['type'] === $tokenType) $i++; |
78 | 78 | else $splitTokens[$i][] = $token; |
79 | 79 | } |
80 | - return array_map(function ($tokens) { |
|
81 | - return new Tokens($tokens); |
|
82 | - }, $splitTokens); |
|
80 | + return array_map(function ($tokens) { |
|
81 | + return new Tokens($tokens); |
|
82 | + }, $splitTokens); |
|
83 | 83 | //return $splitTokens; |
84 | - } |
|
85 | - |
|
86 | - public function trim() { |
|
87 | - $tokens = $this->tokens; |
|
88 | - // Remove end whitespace |
|
89 | - while (end($tokens)['type'] === Tokenizer::WHITESPACE) { |
|
90 | - array_pop($tokens); |
|
91 | - } |
|
92 | - // Remove begining whitespace |
|
93 | - while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) { |
|
94 | - array_shift($tokens); |
|
95 | - } |
|
96 | - return new Tokens($tokens); |
|
97 | - } |
|
98 | - |
|
99 | - public function removeLine() { |
|
100 | - $tokens = $this->tokens; |
|
101 | - foreach ($tokens as &$token) unset($token['line']); |
|
102 | - return new Tokens($tokens); |
|
103 | - } |
|
104 | - |
|
105 | - public function read($offset = 0) { |
|
106 | - return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false; |
|
107 | - } |
|
108 | - |
|
109 | - public function type($offset = 0) { |
|
110 | - return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false; |
|
111 | - } |
|
84 | + } |
|
85 | + |
|
86 | + public function trim() { |
|
87 | + $tokens = $this->tokens; |
|
88 | + // Remove end whitespace |
|
89 | + while (end($tokens)['type'] === Tokenizer::WHITESPACE) { |
|
90 | + array_pop($tokens); |
|
91 | + } |
|
92 | + // Remove begining whitespace |
|
93 | + while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) { |
|
94 | + array_shift($tokens); |
|
95 | + } |
|
96 | + return new Tokens($tokens); |
|
97 | + } |
|
98 | + |
|
99 | + public function removeLine() { |
|
100 | + $tokens = $this->tokens; |
|
101 | + foreach ($tokens as &$token) unset($token['line']); |
|
102 | + return new Tokens($tokens); |
|
103 | + } |
|
104 | + |
|
105 | + public function read($offset = 0) { |
|
106 | + return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false; |
|
107 | + } |
|
108 | + |
|
109 | + public function type($offset = 0) { |
|
110 | + return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false; |
|
111 | + } |
|
112 | 112 | } |
@@ -44,9 +44,13 @@ discard block |
||
44 | 44 | |
45 | 45 | private function getKeyToSlice($tokenType) { |
46 | 46 | $keys = $this->getKeysOfTokenType($tokenType); |
47 | - if (empty($keys)) return false; |
|
47 | + if (empty($keys)) { |
|
48 | + return false; |
|
49 | + } |
|
48 | 50 | $key = $keys[0]; |
49 | - for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i]; |
|
51 | + for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) { |
|
52 | + $key = $keys[$i]; |
|
53 | + } |
|
50 | 54 | return $key; |
51 | 55 | } |
52 | 56 | |
@@ -60,10 +64,17 @@ discard block |
||
60 | 64 | |
61 | 65 | private function sliceTokens($tokenType, $type, $increment = false) { |
62 | 66 | $key = $this->getKeyToSlice($tokenType); |
63 | - if ($key === false) return new Tokens([]); |
|
64 | - if ($increment) $key++; |
|
65 | - if ($type === "from") return new Tokens(array_slice($this->tokens, $key)); |
|
66 | - else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
67 | + if ($key === false) { |
|
68 | + return new Tokens([]); |
|
69 | + } |
|
70 | + if ($increment) { |
|
71 | + $key++; |
|
72 | + } |
|
73 | + if ($type === "from") { |
|
74 | + return new Tokens(array_slice($this->tokens, $key)); |
|
75 | + } else { |
|
76 | + return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
77 | + } |
|
67 | 78 | } |
68 | 79 | |
69 | 80 | public function skip($count) { |
@@ -74,8 +85,11 @@ discard block |
||
74 | 85 | $splitTokens = []; |
75 | 86 | $i = 0; |
76 | 87 | foreach ($this->tokens as $token) { |
77 | - if ($token['type'] === $tokenType) $i++; |
|
78 | - else $splitTokens[$i][] = $token; |
|
88 | + if ($token['type'] === $tokenType) { |
|
89 | + $i++; |
|
90 | + } else { |
|
91 | + $splitTokens[$i][] = $token; |
|
92 | + } |
|
79 | 93 | } |
80 | 94 | return array_map(function ($tokens) { |
81 | 95 | return new Tokens($tokens); |
@@ -98,7 +112,9 @@ discard block |
||
98 | 112 | |
99 | 113 | public function removeLine() { |
100 | 114 | $tokens = $this->tokens; |
101 | - foreach ($tokens as &$token) unset($token['line']); |
|
115 | + foreach ($tokens as &$token) { |
|
116 | + unset($token['line']); |
|
117 | + } |
|
102 | 118 | return new Tokens($tokens); |
103 | 119 | } |
104 | 120 |
@@ -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 | } |
@@ -39,6 +39,9 @@ discard block |
||
39 | 39 | return $this->cache->write($this->file, $rules, $this->import); |
40 | 40 | } |
41 | 41 | |
42 | + /** |
|
43 | + * @param integer $indexStart |
|
44 | + */ |
|
42 | 45 | private function parseTokens($indexStart) { |
43 | 46 | $this->rules = []; |
44 | 47 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
@@ -63,6 +66,9 @@ discard block |
||
63 | 66 | if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
64 | 67 | } |
65 | 68 | |
69 | + /** |
|
70 | + * @param integer $index |
|
71 | + */ |
|
66 | 72 | private function CssToRules($selector, $index, $properties, $line) { |
67 | 73 | $parts = $selector->trim()->splitOnToken(Tokenizer::ARG); |
68 | 74 | $rules = []; |
@@ -86,6 +92,9 @@ discard block |
||
86 | 92 | return $rules; |
87 | 93 | } |
88 | 94 | |
95 | + /** |
|
96 | + * @param integer $indexStart |
|
97 | + */ |
|
89 | 98 | private function processingInstructions($token, $indexStart) { |
90 | 99 | if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
91 | 100 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
@@ -25,14 +25,19 @@ discard block |
||
25 | 25 | $this->file = $tss; |
26 | 26 | $this->rules = $this->cache->load($tss); |
27 | 27 | $this->filePath->addPath(dirname(realpath($tss))); |
28 | - if (empty($this->rules)) $tss = file_get_contents($tss); |
|
29 | - else return; |
|
28 | + if (empty($this->rules)) { |
|
29 | + $tss = file_get_contents($tss); |
|
30 | + } else { |
|
31 | + return; |
|
32 | + } |
|
30 | 33 | } |
31 | 34 | $this->tss = (new SheetTokenizer($tss))->getTokens(); |
32 | 35 | } |
33 | 36 | |
34 | 37 | public function parse($indexStart = 0) { |
35 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
38 | + if (!empty($this->rules)) { |
|
39 | + return $this->rules['rules']; |
|
40 | + } |
|
36 | 41 | $rules = $this->parseTokens($indexStart); |
37 | 42 | usort($rules, [$this, 'sortRules']); |
38 | 43 | $this->checkError($rules); |
@@ -44,8 +49,9 @@ discard block |
||
44 | 49 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
45 | 50 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
46 | 51 | $this->rules = array_merge($this->rules, $processing); |
52 | + } else if ($token['type'] !== Tokenizer::NEW_LINE) { |
|
53 | + $this->addRules($token, $indexStart); |
|
47 | 54 | } |
48 | - else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart); |
|
49 | 55 | } |
50 | 56 | return $this->rules; |
51 | 57 | } |
@@ -53,14 +59,18 @@ discard block |
||
53 | 59 | private function addRules($token, $indexStart) { |
54 | 60 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
55 | 61 | $this->tss->skip(count($selector)); |
56 | - if (count($selector) === 0) return; |
|
62 | + if (count($selector) === 0) { |
|
63 | + return; |
|
64 | + } |
|
57 | 65 | |
58 | 66 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
59 | 67 | $this->rules = $this->writeRule($this->rules, $newRules); |
60 | 68 | } |
61 | 69 | |
62 | 70 | private function checkError($rules) { |
63 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
71 | + if (empty($rules) && count($this->tss) > 0) { |
|
72 | + throw new \Exception('No TSS rules parsed'); |
|
73 | + } |
|
64 | 74 | } |
65 | 75 | |
66 | 76 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -87,7 +97,9 @@ discard block |
||
87 | 97 | } |
88 | 98 | |
89 | 99 | private function processingInstructions($token, $indexStart) { |
90 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
100 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
101 | + return false; |
|
102 | + } |
|
91 | 103 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
92 | 104 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
93 | 105 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -107,7 +119,9 @@ discard block |
||
107 | 119 | |
108 | 120 | private function sortRules($a, $b) { |
109 | 121 | //If they have the same depth, compare on index |
110 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
122 | + if ($a->depth === $b->depth) { |
|
123 | + return $a->index < $b->index ? -1 : 1; |
|
124 | + } |
|
111 | 125 | |
112 | 126 | return ($a->depth < $b->depth) ? -1 : 1; |
113 | 127 | } |
@@ -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 | } |
@@ -79,7 +81,9 @@ discard block |
||
79 | 81 | $selectors = $this->split($css); |
80 | 82 | $xpath = '/'; |
81 | 83 | foreach ($selectors as $selector) { |
82 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
84 | + if (isset($this->translators[$selector->type])) { |
|
85 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
86 | + } |
|
83 | 87 | } |
84 | 88 | |
85 | 89 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -90,7 +94,9 @@ discard block |
||
90 | 94 | private function removeSpacesFromDirectDecend($css) { |
91 | 95 | $tokens = []; |
92 | 96 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
93 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
97 | + foreach ($token->trim() as $t) { |
|
98 | + $tokens[] = $t; |
|
99 | + } |
|
94 | 100 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
95 | 101 | } |
96 | 102 | return new Tokens(array_slice($tokens, 0, -1)); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | $this->translators = [ |
22 | 22 | Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
23 | - Tokenizer::MULTIPLY => function () { return '*'; }, |
|
23 | + Tokenizer::MULTIPLY => function () { return '*'; }, |
|
24 | 24 | '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
25 | 25 | Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
26 | 26 | Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | $functionSet->setElement($element[0]); |
45 | 45 | |
46 | 46 | $attributes = array(); |
47 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
48 | - $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
49 | - } |
|
47 | + foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
48 | + $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
49 | + } |
|
50 | 50 | |
51 | - $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
51 | + $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
52 | 52 | $return = $parser->parseTokens($attr, $attributes); |
53 | 53 | |
54 | 54 | return $return[0] === '' ? false : $return[0]; |
@@ -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 = array(); |
47 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
47 | + foreach ($element[0]->attributes as $attribute_name => $attribute_node) { |
|
48 | 48 | $attributes[$attribute_name] = $attribute_node->nodeValue; |
49 | 49 | } |
50 | 50 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | private function removeSpacesFromDirectDecend($css) { |
92 | 92 | $tokens = []; |
93 | 93 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
94 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
94 | + foreach ($token->trim() as $t) $tokens[] = $t; |
|
95 | 95 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
96 | 96 | } |
97 | 97 | return new Tokens(array_slice($tokens, 0, -1)); |