@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function run(\DomElement $element) { |
32 | 32 | $this->functionSet->setElement($element); |
33 | - if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
33 | + if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)).DIRECTORY_SEPARATOR; |
|
34 | 34 | $this->configLine = $this->line; |
35 | 35 | try { |
36 | 36 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
@@ -30,11 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | public function run(\DomElement $element) { |
32 | 32 | $this->functionSet->setElement($element); |
33 | - if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
33 | + if ($this->file !== null) { |
|
34 | + $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
35 | + } |
|
34 | 36 | $this->configLine = $this->line; |
35 | 37 | try { |
36 | 38 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
37 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
39 | + if (!$this->pseudoMatcher->matches($element)) { |
|
40 | + return; |
|
41 | + } |
|
38 | 42 | |
39 | 43 | // TODO: Have all rule values parsed before running them so that things like `content-append` are not expecting tokens |
40 | 44 | // problem with this is that anything in data changed by run properties is not shown |
@@ -42,10 +46,11 @@ discard block |
||
42 | 46 | |
43 | 47 | foreach ($this->rules as $name => $value) { |
44 | 48 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
45 | - if ($result === false) break; |
|
49 | + if ($result === false) { |
|
50 | + break; |
|
51 | + } |
|
46 | 52 | } |
47 | - } |
|
48 | - catch (\Transphporm\RunException $e) { |
|
53 | + } catch (\Transphporm\RunException $e) { |
|
49 | 54 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
50 | 55 | } |
51 | 56 | } |
@@ -62,9 +67,10 @@ discard block |
||
62 | 67 | if (isset($this->properties[$name])) { |
63 | 68 | try { |
64 | 69 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
65 | - } |
|
66 | - catch (\Exception $e) { |
|
67 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
70 | + } catch (\Exception $e) { |
|
71 | + if ($e instanceof \Transphporm\RunException) { |
|
72 | + throw $e; |
|
73 | + } |
|
68 | 74 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
69 | 75 | } |
70 | 76 | } |
@@ -11,20 +11,28 @@ |
||
11 | 11 | private $lastParentNode; |
12 | 12 | |
13 | 13 | public function match($name, $args, \DomElement $element) { |
14 | - if ($element->parentNode !== $this->lastParentNode) $this->count = 0; |
|
14 | + if ($element->parentNode !== $this->lastParentNode) { |
|
15 | + $this->count = 0; |
|
16 | + } |
|
15 | 17 | |
16 | 18 | $this->lastParentNode = $element->parentNode; |
17 | 19 | |
18 | 20 | |
19 | 21 | |
20 | - if ($name !== 'nth-child') return true; |
|
22 | + if ($name !== 'nth-child') { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $this->count++; |
23 | 27 | $criteria = $args[0]; |
24 | 28 | |
25 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
26 | - else if (!is_numeric($criteria)) throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
27 | - else return $this->count == $criteria; |
|
29 | + if (is_callable([$this, $criteria])) { |
|
30 | + return $this->$criteria($this->count); |
|
31 | + } else if (!is_numeric($criteria)) { |
|
32 | + throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
33 | + } else { |
|
34 | + return $this->count == $criteria; |
|
35 | + } |
|
28 | 36 | } |
29 | 37 | |
30 | 38 | private function odd($num) { |
@@ -49,7 +49,9 @@ discard block |
||
49 | 49 | $this->data = new ValueData($data ? $data : $this->baseData); |
50 | 50 | $this->last = null; |
51 | 51 | |
52 | - if (count($tokens) <= 0) return [$data]; |
|
52 | + if (count($tokens) <= 0) { |
|
53 | + return [$data]; |
|
54 | + } |
|
53 | 55 | |
54 | 56 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) { |
55 | 57 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -71,13 +73,15 @@ discard block |
||
71 | 73 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
72 | 74 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
73 | 75 | private function processDot($token) { |
74 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
75 | - else { |
|
76 | + if ($this->last !== null) { |
|
77 | + $this->data->traverse($this->last); |
|
78 | + } else { |
|
76 | 79 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
77 | 80 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
78 | 81 | $lastResult = $this->result->pop(); |
79 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
80 | - else { |
|
82 | + if ($lastResult) { |
|
83 | + $this->data = new ValueData($lastResult); |
|
84 | + } else { |
|
81 | 85 | $this->processString(['value' => '.']); |
82 | 86 | $this->result->setMode(Tokenizer::CONCAT); |
83 | 87 | } |
@@ -90,12 +94,14 @@ discard block |
||
90 | 94 | $parser = new Value($this->baseData, $this->autoLookup); |
91 | 95 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
92 | 96 | $this->callTransphpormFunctions($token); |
93 | - } |
|
94 | - else { |
|
95 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
96 | - else { |
|
97 | + } else { |
|
98 | + if ($this->last !== null) { |
|
99 | + $this->data->traverse($this->last); |
|
100 | + } else { |
|
97 | 101 | $lastResult = $this->result->pop(); |
98 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
102 | + if ($lastResult) { |
|
103 | + $this->data = new ValueData($lastResult); |
|
104 | + } |
|
99 | 105 | } |
100 | 106 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
101 | 107 | } |
@@ -116,8 +122,7 @@ discard block |
||
116 | 122 | private function processBrackets($token) { |
117 | 123 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
118 | 124 | $this->callTransphpormFunctions($token); |
119 | - } |
|
120 | - else { |
|
125 | + } else { |
|
121 | 126 | $this->processNested($token); |
122 | 127 | } |
123 | 128 | } |
@@ -134,7 +139,9 @@ discard block |
||
134 | 139 | foreach ($this->result->getResult() as $i => $value) { |
135 | 140 | if (is_scalar($value)) { |
136 | 141 | $val = $this->data->read($value); |
137 | - if ($val) $this->result[$i] = $val; |
|
142 | + if ($val) { |
|
143 | + $this->result[$i] = $val; |
|
144 | + } |
|
138 | 145 | } |
139 | 146 | } |
140 | 147 | $this->last = null; |
@@ -146,12 +153,10 @@ discard block |
||
146 | 153 | try { |
147 | 154 | $value = $this->data->extract($this->last, $this->autoLookup); |
148 | 155 | $this->result->processValue($value); |
149 | - } |
|
150 | - catch (\UnexpectedValueException $e) { |
|
156 | + } catch (\UnexpectedValueException $e) { |
|
151 | 157 | if (!$this->autoLookup) { |
152 | 158 | $this->result->processValue($this->last); |
153 | - } |
|
154 | - else { |
|
159 | + } else { |
|
155 | 160 | $this->result->clear(); |
156 | 161 | $this->result[0] = false; |
157 | 162 | } |