@@ -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; |
@@ -105,7 +105,7 @@ |
||
105 | 105 | $string = $this->extractString($i); |
106 | 106 | $length = strlen($string)+1; |
107 | 107 | $char = $this->getChar($char); |
108 | - $string = str_replace('\\' . $char, $char, $string); |
|
108 | + $string = str_replace('\\'.$char, $char, $string); |
|
109 | 109 | $tokens[] = ['type' => self::STRING, 'value' => $string]; |
110 | 110 | return $length; |
111 | 111 | } |
@@ -81,10 +81,15 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | private function processLiterals(&$tokens, $name) { |
84 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
85 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
86 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
87 | - else $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
84 | + if (is_numeric($name)) { |
|
85 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
86 | + } else if ($name == 'true') { |
|
87 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
88 | + } else if ($name == 'false') { |
|
89 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
90 | + } else { |
|
91 | + $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
92 | + } |
|
88 | 93 | } |
89 | 94 | |
90 | 95 | private function doBrackets(&$tokens, $char, $i) { |
@@ -118,7 +123,9 @@ discard block |
||
118 | 123 | private function extractString($pos) { |
119 | 124 | $char = $this->str[$pos]; |
120 | 125 | $end = strpos($this->str, $char, $pos+1); |
121 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
126 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
127 | + $end = strpos($this->str, $char, $end+1); |
|
128 | + } |
|
122 | 129 | |
123 | 130 | return substr($this->str, $pos+1, $end-$pos-1); |
124 | 131 | } |
@@ -127,18 +134,26 @@ discard block |
||
127 | 134 | $close = strpos($this->str, $closeBracket, $open); |
128 | 135 | |
129 | 136 | $cPos = $open+1; |
130 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
137 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
138 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
139 | + } |
|
131 | 140 | return substr($this->str, $open+1, $close-$open-1); |
132 | 141 | } |
133 | 142 | |
134 | 143 | private function identifyChar($chr) { |
135 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
136 | - else return self::NAME; |
|
144 | + if (isset($this->chars[$chr])) { |
|
145 | + return $this->chars[$chr]; |
|
146 | + } else { |
|
147 | + return self::NAME; |
|
148 | + } |
|
137 | 149 | } |
138 | 150 | |
139 | 151 | private function getChar($num) { |
140 | 152 | $chars = array_reverse($this->chars); |
141 | - if (isset($chars[$num])) return $chars[$num]; |
|
142 | - else return false; |
|
153 | + if (isset($chars[$num])) { |
|
154 | + return $chars[$num]; |
|
155 | + } else { |
|
156 | + return false; |
|
157 | + } |
|
143 | 158 | } |
144 | 159 | } |
@@ -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')); |
|
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')); |
|
12 | + } else if (strtolower($values[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |
15 | 19 | \ No newline at end of file |
@@ -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); |
24 | 27 | $return = $parser->parseTokens($args, $data); |
25 | 28 | return $return[0]; |
@@ -1,25 +1,25 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $baseDir; |
|
4 | + private $baseDir; |
|
5 | 5 | |
6 | - public function __construct(&$baseDir) { |
|
7 | - $this->baseDir = &$baseDir; |
|
8 | - } |
|
6 | + public function __construct(&$baseDir) { |
|
7 | + $this->baseDir = &$baseDir; |
|
8 | + } |
|
9 | 9 | |
10 | - public function run(array $args, \DomElement $element = null) { |
|
11 | - $json = $args[0]; |
|
10 | + public function run(array $args, \DomElement $element = null) { |
|
11 | + $json = $args[0]; |
|
12 | 12 | |
13 | - if (trim($json)[0] != '{') { |
|
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | - $json = file_get_contents($json); |
|
17 | - } |
|
13 | + if (trim($json)[0] != '{') { |
|
14 | + $path = $this->baseDir . $json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | + $json = file_get_contents($json); |
|
17 | + } |
|
18 | 18 | |
19 | - $map = json_decode($json, true); |
|
19 | + $map = json_decode($json, true); |
|
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
22 | 22 | |
23 | - return $map; |
|
24 | - } |
|
23 | + return $map; |
|
24 | + } |
|
25 | 25 | } |
@@ -11,14 +11,14 @@ |
||
11 | 11 | $json = $args[0]; |
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
14 | + $path = $this->baseDir.$json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
16 | 16 | $json = file_get_contents($json); |
17 | 17 | } |
18 | 18 | |
19 | 19 | $map = json_decode($json, true); |
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
22 | 22 | |
23 | 23 | return $map; |
24 | 24 | } |
@@ -12,13 +12,17 @@ |
||
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | 14 | $path = $this->baseDir . $json; |
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
15 | + if (!file_exists($path)) { |
|
16 | + throw new \Exception('File does not exist at: ' . $path); |
|
17 | + } |
|
16 | 18 | $json = file_get_contents($json); |
17 | 19 | } |
18 | 20 | |
19 | 21 | $map = json_decode($json, true); |
20 | 22 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) { |
|
24 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
25 | + } |
|
22 | 26 | |
23 | 27 | return $map; |
24 | 28 | } |
@@ -1,25 +1,25 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\Formatter; |
3 | 3 | class Nl2br { |
4 | - public function nl2br($var) { |
|
5 | - $parts = explode("\n", $var); |
|
6 | - $doc = new \DomDocument(); |
|
7 | - $root = $doc->createElement('root'); |
|
8 | - $doc->appendChild($root); |
|
4 | + public function nl2br($var) { |
|
5 | + $parts = explode("\n", $var); |
|
6 | + $doc = new \DomDocument(); |
|
7 | + $root = $doc->createElement('root'); |
|
8 | + $doc->appendChild($root); |
|
9 | 9 | |
10 | - foreach ($parts as $key => $part) { |
|
11 | - $new = $doc->createTextNode($part); |
|
12 | - $doc->documentElement->appendChild($new); |
|
13 | - if ($key !== count($parts)-1) { |
|
14 | - $br = $doc->createElement('br'); |
|
15 | - $doc->documentElement->appendChild($br); |
|
16 | - } |
|
17 | - } |
|
10 | + foreach ($parts as $key => $part) { |
|
11 | + $new = $doc->createTextNode($part); |
|
12 | + $doc->documentElement->appendChild($new); |
|
13 | + if ($key !== count($parts)-1) { |
|
14 | + $br = $doc->createElement('br'); |
|
15 | + $doc->documentElement->appendChild($br); |
|
16 | + } |
|
17 | + } |
|
18 | 18 | |
19 | - return $this->getContent($doc); |
|
20 | - } |
|
19 | + return $this->getContent($doc); |
|
20 | + } |
|
21 | 21 | |
22 | - private function getContent($document) { |
|
22 | + private function getContent($document) { |
|
23 | 23 | $newNode = $document->documentElement; |
24 | 24 | $result = []; |
25 | 25 | if ($newNode->tagName === 'root') { |
@@ -67,12 +67,16 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function loadProperties(Hook\PropertyHook $hook) { |
70 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
70 | + foreach ($this->properties as $name => $property) { |
|
71 | + $hook->registerProperty($name, $property); |
|
72 | + } |
|
71 | 73 | } |
72 | 74 | |
73 | 75 | public function createPseudoMatcher($pseudo) { |
74 | 76 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
78 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
79 | + } |
|
76 | 80 | return $pseudoMatcher; |
77 | 81 | } |
78 | 82 |
@@ -34,6 +34,9 @@ discard block |
||
34 | 34 | return $this->data->$func(...$args); |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param Value $parser |
|
39 | + */ |
|
37 | 40 | public function parseNested($parser, $token, $funcName) { |
38 | 41 | $args = $parser->parseTokens($token['value'], $this->data); |
39 | 42 | if ($args[0] == $this->data) $args = []; |
@@ -49,6 +52,9 @@ discard block |
||
49 | 52 | else return call_user_func_array([$obj, $func], $args); |
50 | 53 | } |
51 | 54 | |
55 | + /** |
|
56 | + * @param boolean $autoLookup |
|
57 | + */ |
|
52 | 58 | public function extract($last, $autoLookup) { |
53 | 59 | if ($autoLookup && isset($this->data->{$last})) { |
54 | 60 | return $this->data->{$last}; |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | public function extract($last, $autoLookup) { |
53 | 53 | $value = $this->read($last); |
54 | - if ($value && ($autoLookup || is_array($this->data)) ) { |
|
54 | + if ($value && ($autoLookup || is_array($this->data))) { |
|
55 | 55 | return $value; |
56 | 56 | } |
57 | 57 | throw new \UnexpectedValueException('Not found'); |
@@ -14,16 +14,23 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function traverse($key) { |
17 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
18 | - else if (is_array($this->data) && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
17 | + if (isset($this->data->{$key})) { |
|
18 | + $this->data = $this->data->{$key}; |
|
19 | + } else if (is_array($this->data) && isset($this->data[$key])) { |
|
20 | + $this->data = $this->data[$key]; |
|
21 | + } |
|
19 | 22 | } |
20 | 23 | |
21 | 24 | public function read($value) { |
22 | 25 | if (is_array($this->data)) { |
23 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
26 | + if (isset($this->data[$value])) { |
|
27 | + return $this->data[$value]; |
|
28 | + } |
|
29 | + } else if (isset($this->data->$value)) { |
|
30 | + return $this->data->$value; |
|
31 | + } else { |
|
32 | + return false; |
|
24 | 33 | } |
25 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
26 | - else return false; |
|
27 | 34 | } |
28 | 35 | |
29 | 36 | public function isFunctionSet() { |
@@ -36,7 +43,9 @@ discard block |
||
36 | 43 | |
37 | 44 | public function parseNested($parser, $token, $funcName) { |
38 | 45 | $args = $parser->parseTokens($token['value'], $this->data); |
39 | - if ($args[0] == $this->data) $args = []; |
|
46 | + if ($args[0] == $this->data) { |
|
47 | + $args = []; |
|
48 | + } |
|
40 | 49 | return $this->callFunc($funcName, $args, $this->data); |
41 | 50 | } |
42 | 51 | |
@@ -45,8 +54,11 @@ discard block |
||
45 | 54 | } |
46 | 55 | |
47 | 56 | private function callFuncOnObject($obj, $func, $args) { |
48 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
49 | - else return call_user_func_array([$obj, $func], $args); |
|
57 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
58 | + return call_user_func_array($obj->$func, $args); |
|
59 | + } else { |
|
60 | + return call_user_func_array([$obj, $func], $args); |
|
61 | + } |
|
50 | 62 | } |
51 | 63 | |
52 | 64 | public function extract($last, $autoLookup) { |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | $this->data = new ValueData($data); |
52 | 52 | $this->last = null; |
53 | 53 | |
54 | - if (empty($tokens)) return [$data]; |
|
54 | + if (empty($tokens)) { |
|
55 | + return [$data]; |
|
56 | + } |
|
55 | 57 | |
56 | 58 | foreach ($tokens as $token) { |
57 | 59 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -66,8 +68,7 @@ discard block |
||
66 | 68 | |
67 | 69 | if ($this->result->getMode() == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) { |
68 | 70 | $this->result->setMode(Tokenizer::NOT); |
69 | - } |
|
70 | - else { |
|
71 | + } else { |
|
71 | 72 | $this->result->setMode($token['type']); |
72 | 73 | $this->last = null; |
73 | 74 | } |
@@ -77,8 +78,11 @@ discard block |
||
77 | 78 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
78 | 79 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
79 | 80 | private function processDot($token) { |
80 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
81 | - else $this->data = new ValueData($this->result->pop()); |
|
81 | + if ($this->last !== null) { |
|
82 | + $this->data->traverse($this->last); |
|
83 | + } else { |
|
84 | + $this->data = new ValueData($this->result->pop()); |
|
85 | + } |
|
82 | 86 | |
83 | 87 | $this->last = null; |
84 | 88 | } |
@@ -87,9 +91,10 @@ discard block |
||
87 | 91 | $parser = new Value($this->baseData, $this->autoLookup); |
88 | 92 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
89 | 93 | $this->callTransphpormFunctions($token); |
90 | - } |
|
91 | - else { |
|
92 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
94 | + } else { |
|
95 | + if ($this->last !== null) { |
|
96 | + $this->data->traverse($this->last); |
|
97 | + } |
|
93 | 98 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
94 | 99 | } |
95 | 100 | } |
@@ -111,12 +116,10 @@ discard block |
||
111 | 116 | private function processBrackets($token) { |
112 | 117 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
113 | 118 | $this->callTransphpormFunctions($token); |
114 | - } |
|
115 | - else if ($this->data->isFunctionSet()) { |
|
119 | + } else if ($this->data->isFunctionSet()) { |
|
116 | 120 | $this->result = $this->result->processValue($this->data->call($this->last, [$token['value']])); |
117 | 121 | $this->last = null; |
118 | - } |
|
119 | - else { |
|
122 | + } else { |
|
120 | 123 | $this->processNested($token); |
121 | 124 | } |
122 | 125 | } |
@@ -133,7 +136,9 @@ discard block |
||
133 | 136 | foreach ($this->result->getResult() as $i => $value) { |
134 | 137 | if (is_scalar($value)) { |
135 | 138 | $val = $this->data->read($value); |
136 | - if ($val) $this->result[$i] = $val; |
|
139 | + if ($val) { |
|
140 | + $this->result[$i] = $val; |
|
141 | + } |
|
137 | 142 | } |
138 | 143 | } |
139 | 144 | $this->last = null; |
@@ -145,12 +150,10 @@ discard block |
||
145 | 150 | try { |
146 | 151 | $value = $this->data->extract($this->last, $this->autoLookup); |
147 | 152 | $this->result->processValue($value); |
148 | - } |
|
149 | - catch (\UnexpectedValueException $e) { |
|
153 | + } catch (\UnexpectedValueException $e) { |
|
150 | 154 | if (!$this->autoLookup) { |
151 | 155 | $this->result->processValue($this->last); |
152 | - } |
|
153 | - else { |
|
156 | + } else { |
|
154 | 157 | $this->result->clear(); |
155 | 158 | $this->result[0] = false; |
156 | 159 | } |