@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | elseif (in_array($first, ['?', ':'])) $this->onSetElement($nodeValue); |
183 | 183 | elseif (in_array($first, ['!', '&', '*'])) $this->onNodeAction($nodeValue); |
184 | 184 | else { |
185 | - $characters = [ '#' => [Y::COMMENT, $v], |
|
185 | + $characters = ['#' => [Y::COMMENT, $v], |
|
186 | 186 | '%' => [Y::DIRECTIVE, $v], |
187 | 187 | '>' => [Y::LITT_FOLDED, null], |
188 | 188 | '|' => [Y::LITT, null] |
@@ -251,28 +251,28 @@ discard block |
||
251 | 251 | private function onCompact($value) |
252 | 252 | { |
253 | 253 | $this->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
254 | - if (json_last_error() === JSON_ERROR_NONE){ |
|
254 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
255 | 255 | $this->type = Y::JSON; |
256 | 256 | return; |
257 | 257 | } |
258 | 258 | $this->value = new NodeList(); |
259 | - if (preg_match(R::MAPPING, $value)){ |
|
259 | + if (preg_match(R::MAPPING, $value)) { |
|
260 | 260 | $this->type = Y::COMPACT_MAPPING; |
261 | 261 | $this->value->type = Y::COMPACT_MAPPING; |
262 | - preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches); |
|
262 | + preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches); |
|
263 | 263 | foreach ($matches['k'] as $index => $property) { |
264 | 264 | $n = new Node('', $this->line); |
265 | 265 | $n->type = Y::KEY; |
266 | - $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ? |
|
266 | + $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ? |
|
267 | 267 | $n->value = new Node($matches['v'][$index], $this->line); |
268 | 268 | $this->value->push($n); |
269 | 269 | } |
270 | 270 | return; |
271 | 271 | } |
272 | - if (preg_match(R::SEQUENCE, $value)){ |
|
272 | + if (preg_match(R::SEQUENCE, $value)) { |
|
273 | 273 | $this->type = Y::COMPACT_SEQUENCE; |
274 | 274 | $this->value->type = Y::COMPACT_SEQUENCE; |
275 | - preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches); |
|
275 | + preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches); |
|
276 | 276 | foreach ($matches['item'] as $key => $item) { |
277 | 277 | $i = new Node('', $this->line); |
278 | 278 | $i->type = Y::ITEM; |
@@ -68,8 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function getParent(int $indent = null, $type = 0):Node |
70 | 70 | { |
71 | - if ($this->type === Y::ROOT) return $this; |
|
72 | - if (!is_int($indent)) return $this->parent ?? $this; |
|
71 | + if ($this->type === Y::ROOT) { |
|
72 | + return $this; |
|
73 | + } |
|
74 | + if (!is_int($indent)) { |
|
75 | + return $this->parent ?? $this; |
|
76 | + } |
|
73 | 77 | $cursor = $this; |
74 | 78 | while ($cursor instanceof Node && $cursor->indent >= $indent) { |
75 | 79 | if ($cursor->indent === $indent && $cursor->type !== $type) { |
@@ -101,7 +105,7 @@ discard block |
||
101 | 105 | if (is_null($current)) { |
102 | 106 | $this->value = $child; |
103 | 107 | return; |
104 | - }elseif ($current instanceof Node) { |
|
108 | + } elseif ($current instanceof Node) { |
|
105 | 109 | if ($current->type & Y::LITTERALS) { |
106 | 110 | $this->value = new NodeList(); |
107 | 111 | $this->value->type = $current->type; |
@@ -176,12 +180,17 @@ discard block |
||
176 | 180 | { |
177 | 181 | $v = ltrim(substr($nodeValue, 1)); |
178 | 182 | $first = $nodeValue[0]; |
179 | - if ($first === "-") $this->onHyphen($nodeValue); |
|
180 | - elseif (in_array($first, ['"', "'"])) $this->onQuoted($nodeValue); |
|
181 | - elseif (in_array($first, ['{', '['])) $this->onCompact($nodeValue); |
|
182 | - elseif (in_array($first, ['?', ':'])) $this->onSetElement($nodeValue); |
|
183 | - elseif (in_array($first, ['!', '&', '*'])) $this->onNodeAction($nodeValue); |
|
184 | - else { |
|
183 | + if ($first === "-") { |
|
184 | + $this->onHyphen($nodeValue); |
|
185 | + } elseif (in_array($first, ['"', "'"])) { |
|
186 | + $this->onQuoted($nodeValue); |
|
187 | + } elseif (in_array($first, ['{', '['])) { |
|
188 | + $this->onCompact($nodeValue); |
|
189 | + } elseif (in_array($first, ['?', ':'])) { |
|
190 | + $this->onSetElement($nodeValue); |
|
191 | + } elseif (in_array($first, ['!', '&', '*'])) { |
|
192 | + $this->onNodeAction($nodeValue); |
|
193 | + } else { |
|
185 | 194 | $characters = [ '#' => [Y::COMMENT, $v], |
186 | 195 | '%' => [Y::DIRECTIVE, $v], |
187 | 196 | '>' => [Y::LITT_FOLDED, null], |