@@ -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) { |
@@ -100,7 +104,7 @@ discard block |
||
| 100 | 104 | if (is_null($this->value)) { |
| 101 | 105 | $this->value = $child; |
| 102 | 106 | return; |
| 103 | - }elseif ($this->value instanceof Node) { |
|
| 107 | + } elseif ($this->value instanceof Node) { |
|
| 104 | 108 | if ($this->value->type & Y::LITTERALS) { |
| 105 | 109 | $type = $this->value->type; |
| 106 | 110 | $this->value = new NodeList(); |
@@ -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], |
@@ -35,10 +35,14 @@ discard block |
||
| 35 | 35 | $documents = []; |
| 36 | 36 | $_root->value instanceof NodeList && $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
| 37 | 37 | foreach ($_root->value as $child) { |
| 38 | - if ($child->type & Y::DOC_START) $totalDocStart++; |
|
| 38 | + if ($child->type & Y::DOC_START) { |
|
| 39 | + $totalDocStart++; |
|
| 40 | + } |
|
| 39 | 41 | //if 0 or 1 DOC_START = we are still in first document |
| 40 | 42 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0; |
| 41 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList(); |
|
| 43 | + if (!isset($documents[$currentDoc])) { |
|
| 44 | + $documents[$currentDoc] = new NodeList(); |
|
| 45 | + } |
|
| 42 | 46 | $documents[$currentDoc]->push($child); |
| 43 | 47 | } |
| 44 | 48 | $content = []; |
@@ -63,7 +67,9 @@ discard block |
||
| 63 | 67 | */ |
| 64 | 68 | private static function build(object $node, &$parent = null) |
| 65 | 69 | { |
| 66 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
| 70 | + if ($node instanceof NodeList) { |
|
| 71 | + return self::buildNodeList($node, $parent); |
|
| 72 | + } |
|
| 67 | 73 | return self::buildNode($node, $parent); |
| 68 | 74 | } |
| 69 | 75 | |
@@ -145,7 +151,9 @@ discard block |
||
| 145 | 151 | private static function handleReference($node, $parent) |
| 146 | 152 | { |
| 147 | 153 | $tmp = is_null($node->value) ? null : self::build($node->value, $parent); |
| 148 | - if ($node->type === Y::REF_DEF) self::$_root->addReference($node->identifier, $tmp); |
|
| 154 | + if ($node->type === Y::REF_DEF) { |
|
| 155 | + self::$_root->addReference($node->identifier, $tmp); |
|
| 156 | + } |
|
| 149 | 157 | return self::$_root->getReference($node->identifier); |
| 150 | 158 | } |
| 151 | 159 | |
@@ -233,7 +241,9 @@ discard block |
||
| 233 | 241 | $list->rewind(); |
| 234 | 242 | $refIndent = $list->current()->indent; |
| 235 | 243 | //remove trailing blank |
| 236 | - while ($list->top()->type & Y::BLANK) $list->pop(); |
|
| 244 | + while ($list->top()->type & Y::BLANK) { |
|
| 245 | + $list->pop(); |
|
| 246 | + } |
|
| 237 | 247 | $result = ''; |
| 238 | 248 | $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
| 239 | 249 | foreach ($list as $child) { |
@@ -242,10 +252,12 @@ discard block |
||
| 242 | 252 | } else { |
| 243 | 253 | $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent); |
| 244 | 254 | if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
| 245 | - if ($result[-1] === $separator) |
|
| 246 | - $result[-1] = "\n"; |
|
| 247 | - if ($result[-1] === "\n") |
|
| 248 | - $result .= $val; |
|
| 255 | + if ($result[-1] === $separator) { |
|
| 256 | + $result[-1] = "\n"; |
|
| 257 | + } |
|
| 258 | + if ($result[-1] === "\n") { |
|
| 259 | + $result .= $val; |
|
| 260 | + } |
|
| 249 | 261 | continue; |
| 250 | 262 | } |
| 251 | 263 | $result .= $val.$separator; |
@@ -267,7 +279,9 @@ discard block |
||
| 267 | 279 | $built = is_object($node->value) ? self::build($node->value) : null; |
| 268 | 280 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
| 269 | 281 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 270 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
| 282 | + if (empty($key)) { |
|
| 283 | + throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
| 284 | + } |
|
| 271 | 285 | $parent->{trim($key, '\'" ')} = null; |
| 272 | 286 | } |
| 273 | 287 | |